Hi all,
is it possible to dynamically add key items to an already existing key,
belonging to a lattice xyplot?
This is what I do: I make an xyplot with an initial key. Later on, I
want to extend this key with more items, as more lines are added to the
plot (lines are added using trellis.focus("panel")).
I guess I need some function to access the key panel in order to extend
it, i.e., by using something like trellis.focus("legend"), but this
only
yields errors.
Also, in the lattice documentation, the only separate key function I
could find is draw.key(), no functions to add individual key items.
anyone has more info on dynamically adding items to keys in xyplots?
thanks,
Bram Kuijper
this is the code for my lattice xyplot plot:
print(xyplot(current_data$FemDiploidUninf ~ current_data$generation,
ylim=c(0,2000),
scales=list(x=list(tick.number=4)),
par.settings=list(plot.line=list(col='red')),
type="l",
key=list(text=list(c("blah","blah2")),x=0.5,y=0.5,lines=list(type="l",col="red")),
),newpage=FALSE)
# add another line to plot
trellis.focus("panel")
...
trellis.unfocus()
# focus on the existing key
trellis.focus("legend",1,1,highlight=FALSE)
??
On 2/5/08, Bram Kuijper <a.l.w.kuijper at rug.nl> wrote:> Hi all, > > is it possible to dynamically add key items to an already existing key, > belonging to a lattice xyplot?No. -Deepayan> This is what I do: I make an xyplot with an initial key. Later on, I > want to extend this key with more items, as more lines are added to the > plot (lines are added using trellis.focus("panel")). > > I guess I need some function to access the key panel in order to extend > it, i.e., by using something like trellis.focus("legend"), but this only > yields errors. > > Also, in the lattice documentation, the only separate key function I > could find is draw.key(), no functions to add individual key items. > > anyone has more info on dynamically adding items to keys in xyplots? > > thanks, > Bram Kuijper > > this is the code for my lattice xyplot plot: > > print(xyplot(current_data$FemDiploidUninf ~ current_data$generation, > ylim=c(0,2000), > scales=list(x=list(tick.number=4)), > par.settings=list(plot.line=list(col='red')), > type="l", > key=list(text=list(c("blah","blah2")),x=0.5,y=0.5,lines=list(type="l",col="red")), > ),newpage=FALSE) > > # add another line to plot > trellis.focus("panel") > ... > trellis.unfocus() > > # focus on the existing key > trellis.focus("legend",1,1,highlight=FALSE) > > ?? > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >
On Feb 5, 2008 3:50 AM, Bram Kuijper <a.l.w.kuijper at rug.nl> 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: install.packages("ggplot2") library(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 http://had.co.nz/ggplot2 Hadley -- http://had.co.nz/