[R] Fwd: correct line types in lattice legends

Deepayan Sarkar deepayan.sarkar at gmail.com
Sat Jun 6 19:53:29 CEST 2009


[Forgot to CC r-help]

---------- Forwarded message ----------
From: Deepayan Sarkar <deepayan.sarkar at gmail.com>
To: Gerrit Draisma <g.draisma at erasmusmc.nl>


On 6/6/09, Gerrit Draisma <g.draisma at erasmusmc.nl> wrote:
 > Hallo R-users,
 >  I do not understand how to specify the correct
 >  line and symbol types in the legends of a lattice xyplot.
 >  This is what I tried, but the line types and symbol  in the
 >  graph are not seen in the legend.
 >  Any help is appreciated.
 >
 >  Thanks,
 >  Gerrit.
 >
 >  library(lattice)
 >  s<-rep(1:3,len=10)
 >  x<- 1:10
 >  y<- x+s+rnorm(10)
 >  d<-data.frame(s,x,y)
 >  xyplot(y~x, groups=s,data=d, type="b",


Instead of


   pch=1:3,lty=1:3,


try

   par.settings = simpleTheme(pch=1:3,lty=1:3),


 > auto.key=list(text=c("A","B","C"),points=FALSE,lines=TRUE,
 >   type="b",lty=1:3,divide=1,pch=1:3,columns=3))


The lty and pch in auto.key are not used.

 Alternatively, you could use the classic approach using key, where you
 need specify all parameters again in the key. You are already pretty
 close to that:


 xyplot(y~x, groups=s,data=d, type="b", pch=1:3,lty=1:3,

       key=list(text=list(c("A","B","C")),
                lines=list(lty=1:3, pch=1:3, type="b"),
                divide=1, columns=3))

 You'll need to add matching colors as well.


 -Deepayan




More information about the R-help mailing list