[R] lattice garphs: combining multiple scatterplots and addinglegend

Bert Gunter gunter.berton at gene.com
Mon Apr 12 19:41:10 CEST 2010


There us no "groups" argument in your xyplot call, so how is auto.key
supposed to define a legend? (and note that auto.key should be a logical not
a list).

Please re-read the auto.key section in the xyplot man page.

Bert Gunter
Genentech Nonclinical Biostatistics
 
 -----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
Behalf Of Jannis
Sent: Monday, April 12, 2010 10:20 AM
To: R-help at r-project.org
Subject: [R] lattice garphs: combining multiple scatterplots and
addinglegend

Dear List members,


its me again, fighting with lattice graphics. I am trying to plot a world
map, add some points on different locations with different colors and add a
legend, but did not succeed yet with the legend. Here is my code:


library(fields)

# Data for demonstration

data_x = c(0,50,60)
data_y = c(0,0,0)
cols   = c(1,2,3)
data(world.dat)

#print map
all=xyplot(world.dat$y  ~ world.dat$x,
   type=c('l'),col="black",xlab="",ylab="",
   ylim=c(-55,80),xlim=c(-170,175),pch=20,cex=0.2,
   auto.key = list(x=0,y=0,text=c('test1','test2','test3')))
print(all,position=c(0,0,1,.7),more=T)

#add points
trellis.focus(highlight=FALSE)
lpoints(data_x,data_y,pch=20,col=cols)
update(all,auto.key = list(x=0,y=0,text=c('test1','test2','test3')))


The plots are produced correctly, but the legend is still missing. Could
anyone give me some hints?
There is probably a much more elegant way how to combine the two plots but i
did not manage to understand the usage of these different panel functions.
There is most probably no way around the Trellis book, but I could not yet
buy it....


Thanks for your help
Jannis


__________________________________________________
Do You Yahoo!?
Sie sind S
ssenmails. 
http://mail.yahoo.com

______________________________________________
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.



More information about the R-help mailing list