Re: [R] dynamically add items to key of lattice xyplot

From: hadley wickham <>
Date: Tue, 5 Feb 2008 16:12:53 -0600

On Feb 5, 2008 3:50 AM, Bram Kuijper <> wrote:
> Hi all,
> is it possible to dynamically add key items to an already existing key,
> belonging to a lattice xyplot?

It's not lattice, but this is pretty easy to do with ggplot2:


qplot(mpg, wt, data=mtcars, colour="1") + geom_point(aes(x = mpg ^ 2, colour="2")) + geom_point(aes(x=mpg^3, colour="3")) +
scale_colour_discrete("x power")

each time you add a new layer, all of the scale limits are recalculated to ensure that all data is displayed. You can read more about ggplot2 at



______________________________________________ mailing list
PLEASE do read the posting guide
and provide commented, minimal, self-contained, reproducible code.
Received on Tue 05 Feb 2008 - 22:16:33 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 05 Feb 2008 - 22:30:11 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive