[R] pairs() Legend

Duncan Murdoch murdoch at stats.uwo.ca
Tue Sep 25 15:26:51 CEST 2001

On Tue, 25 Sep 2001 22:07:15 +1200 (NZST), you wrote in message
<Pine.SOL.4.21.0109252204270.17045-100000 at stat1.stat.auckland.ac.nz>:

>Is it possible to create a legend in a pairs() plot?
>For example, suppose I have the following R codes:
> data(iris)
> pairs(iris[1:4], main = "Anderson's Iris Data -- 3 species", 
>       pch = 21, bg = c("red", "green3", "blue")[codes(iris$Species)])
>How can I created a legend that shows which colour represents to which
>Iris species?

The legend function is the general purpose way to put a legend on a
plot.  For the legend you want, you'd use

 legend(locator(),legend=levels(iris$Species), pt.bg =  c("red",
"green3", "blue"), pch=21)

The locator() function lets you position it manually.  You might want
to put in fixed values, instead.

The default pairs() call gives no space for a legend, so you'll
probably want to use "oma=c(4,4,6,10)" or something to give yourself
some extra space for the legend.

Duncan Murdoch
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch

More information about the R-help mailing list