For the iris data, we get the scatter plot using the pairs() function as below:
pairs(iris[1:4],
main = "Edgar Anderson's Iris Data",
lower.panel=panel.pearson,
pch = 21,
bg = c("red", "green3", "blue")[unclass(iris$Species)])
With the function panel.pearson defined as follows:
panel.pearson <- function(x, y, ...) {
horizontal <- (par("usr")[1] + par("usr")[2]) / 2;
vertical <- (par("usr")[3] + par("usr")[4]) / 2;
text(horizontal, vertical, format(abs(cor(x,y)), digits=2)) }
I needed to convert the lower panel to correlation matrix and remove the labels from the diagonal and put them along the right and bottom axes. I tried the following:
pairs(iris[1:4],
main = "Edgar Anderson's Iris Data",
labels=NULL,
lower.panel=panel.pearson,
xaxt='n',
yaxt='n',
pch = 21,
bg = c("red", "green3", "blue")[unclass(iris$Species)])
This gives me what I need. Except that I do not understand how to get the labels on the bottom and right axes (the variable labels, I mean, Sepal.Length, Sepal.Width etc..). Any help is tremendously appreciated. Thanks!
panel.pearson
. – Stephan Kolassa