[R] How to overlay lines and rectangles in lattice plot key

David Winsemius dwinsemius at comcast.net
Thu Dec 29 06:00:35 CET 2016


> On Dec 28, 2016, at 6:50 PM, sbihorel <Sebastien.Bihorel at cognigencorp.com> wrote:
> 
> Hi,
> 
> I would like to create a custom key for a lattice xyplot in which line elements are displayed on top of rectangle elements. In the example code below, the lines and rectangles are shown side by side (the legend itself is meaningless, but that is not the point). Is there a way to overlay these key elements (but not the text)?
> 
> Thanks
> 
> xyplot(Sepal.Length + Sepal.Width ~ Petal.Length + Petal.Width,
>  iris,
>  type = c("p", "r"),
>  jitter.x = TRUE,
>  jitter.y = TRUE,
>  factor = 5,
>  key = list(
>    column=4,
>    text=list(lab=letters[1:4]),
>    lines=list(col=1:4, pch=1:4, type='b'),
>    rectangles=list(col=1:4, alpha=0.25, border=FALSE)
>  )
> )

I'm not seeing the result that you describe. Attached is the pdf that comes from:

 pdf(); print( xyplot(Sepal.Length + Sepal.Width ~ Petal.Length + Petal.Width,
 iris,
 type = c("p", "r"),
 jitter.x = TRUE,
 jitter.y = TRUE,
 factor = 5,
 key = list(
   column=4,
   text=list(lab=letters[1:4]),
   lines=list(col=1:4, pch=1:4, type='b'),
   rectangles=list(col=1:4, alpha=0.25, border=FALSE)
 )
) ); dev.off()

-------------- next part --------------
A non-text attachment was scrubbed...
Name: Rplots.pdf
Type: application/pdf
Size: 10022 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20161228/4a4ed380/attachment.pdf>
-------------- next part --------------


-- 
David Winsemius
Alameda, CA, USA



More information about the R-help mailing list