[R] Alignment and Labeling of a color key in a xyplot?

Gabor Grothendieck ggrothendieck at gmail.com
Tue Jan 1 18:11:38 CET 2008


Is this what you want (same as your except the draw.key and
reference to grid is removed key=... is added in the xyplot call:

library(lattice)
x <- 1:3
colorseq < c(0.2, 0.5, 0.8)
mycolors <- gray(colorseq)
xyplot(x ~ x, col = mycolors, aspect = 1,
  key = list(rect = list(col = mycolors), text = list(letters[1:3]),
     space = "right")
)


On Jan 1, 2008 6:36 AM, Hofert Marius <m_hofert at web.de> wrote:
> Happy New Year to all R users!
>
> I have two short questions concerning a xyplot with a color key:
>
> 1) How do I properly place (align) the color key beside the xyplot?
> As you can see from the code listed below, the placement of the color
> key is not correct. I would like the upper and lower end point of the
> color key to be perfectly aligned with the upper and lower line of
> the xyplot. Adjusting the viewport-arguments below is tedious and
> also does not help if you want the print the plot in a postscript
> file (see the commented lines below).
>
> 2) How do I put a label on the color key?
> I would like to give the color key a label as the label 'x' for the y-
> axis, so it should be vertically printed and located to the right of
> the color key. I tried to give the 'key' argument in 'draw.colorkey'
> some arguments, but I could not manage to put a label on the color key.
>
> Thanks very much.
>
> Marius
>
> library(lattice)
> library(grid)
> x=c(1,2,3)
> colorseq=c(0.2,0.5,0.8)
> mycolors=gray(colorseq)
> #trellis.device(postscript,horizontal=F,onefile=F,file="~/testplot.ps")
> xyplot(x~x,col=mycolors,aspect=1)
> draw.colorkey(key=list(at=seq(1,3,length=4),col=mycolors,text=list(c
> ("test"))),draw=TRUE,vp=viewport(x=1,y=0.6,height=0.8))
> #dev.off()
>
> ______________________________________________
> 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