I use pairs(iris)to show the possible relationships between the four variables (Sepal.length, Sepal.width, Petal.length, Petal.width) in the Iris handwriting dataset.
When I add color option ...
pairs(iris[, 1:4], col = iris$Species)
... I see the differences between the three species (Iris setosa, Iris virginica and Iris versicolor), but the code, as I wrote, does not associate colors with the species. In other words, there is no legend or anything that acts like a legend.
So, someone suggested adding the following line of code below ...
par(xpd = TRUE)
legend( "bottomright", fill = unique(iris$Species),
legend = c( levels(iris$Species) ) )
... and although I get a window with a legend, the legend field is superimposed on the data on the pairs () graph.
Is there a way to create something like a legend window for pairs()that will not overlap with the data view itself?