[R] lattice garphs: combining multiple scatterplots and adding legend

Jannis bt_jannis at yahoo.de
Mon Apr 12 19:20:15 CEST 2010


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



More information about the R-help mailing list