Skip to content
Prev 59981 / 398502 Next

Making legend() look like my plot()

Hi
Uwe Ligges wrote:
For example, ...

     xyplot(Sepal.Length + Sepal.Width ~ Petal.Length + Petal.Width |
            Species,
            data = iris, scales = "free", layout = c(2, 2),
            auto.key = TRUE)

... and even in traditional graphics there are some automated legends ...

       a <- expand.grid(1:20, 1:20)
       b <- matrix(a[,1] + a[,2], 20)
       filled.contour(x = 1:20, y = 1:20, z = b)

... but this is only really possible when an entire plot is produced 
from a single function call (so everything is known about the plot at 
once).  The general problem is that R tries to be useful by allowing you 
to add extra lines, points, ... to any part of a plot, but the price of 
this flexibility is that R has no idea what is actually a data series in 
a plot and what is just some piece of decoration.  With the grid 
graphics package, it is possible to build up a graphical object 
representing a plot, so it might then be possible to make the 
distinction between output representing data series and other stuff; 
and here we encounter your previous statement, 'that would be cool if I 
had time' :)

Paul