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

sbihorel Sebastien.Bihorel at cognigencorp.com
Thu Dec 29 12:32:15 CET 2016


Thanks to all the persons who replied,

I was hoping for a quick "grid-free" solution but I guess it is not 
Christmas time anymore :D

Grid coding it is.


On 12/29/2016 12:13 AM, Richard M. Heiberger wrote:
> Yes, but it will probably require work.  I think you will need to
> write a grob that does what you want
> and then use the grob in a legend statement in the xyplot.
>
> Start with the 'legend' argument to xyplot (about line 940 in ?xyplot).
> You will probably need to work directly with grid functions and will
> find Paul Murrell's book very helpful.
> https://www.crcpress.com/R-Graphics/Murrell/p/book/9781584884866
>
> Rich
>
> On Wed, Dec 28, 2016 at 9: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)
>>    )
>> )
>>
>> ______________________________________________
>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> 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.

-- 
Sebastien Bihorel
Associate Director, Pharmacometrics
Buffalo Office: +1-716-633-3463 ext. 323 | Website 
<http://www.cognigencorp.com>
<http://www.simulations-plus.com/Default.aspx>


More information about the R-help mailing list