[R] Specifying point symbol fill colour in lattice xyplot keys

Wayne Rochester wayne.rochester at csiro.au
Mon Mar 18 04:10:00 CET 2013


Dear Duncan,

Many thanks for that advice. It looked like it should work, but it only 
affected the points on the graph, and not the ones on the key. Looking 
at the lattice source, the draw.key function doesn't seem to consult 
many settings.

I'm now pretty confident that the fill parameter is not having an affect 
due to a small bug in the lattice draw.key function. Within the draw.key 
function there's a function called process.key, whose return value 
provides a template that determines which parameters from the 'points' 
key item will be copied to the output key. It takes a bunch of 
arguments, including 'fill', and includes all arguments -- except for 
'fill' -- in its return value. If I add 'fill=fill' to its return value 
list, then my example code works as expected.

Best wishes,

Wayne Rochester
CSIRO, Brisbane, Australia

-------- Original Message --------
Subject: Re: Specifying point symbol fill colour in lattice xyplot keys
From: Wayne Rochester <wayne.rochester at csiro.au>
To: Wayne Rochester <Wayne.Rochester at csiro.au>
Date: 18/03/13 11:54
> Hi Wayne
>
> Try this
>
> library(lattice)
>
> xyplot(1:10 ~ 1:10,
>        par.settings = list(plot.symbol = list(col = "blue",
>                                               fill = "red",
>                                               cex = 1,
>                                               pch = 21)),
>        type = "p",
>        key = list(points = list(col = "blue",
>                                 fill = "red",
>                                 cex = 3,
>                                 pch = 21))
>
> )
>
> I sometimes have trouble with passing colours etc to panels and keys
> in lattice but this seems to work.
> If you have groups change plot.symbol to superpose.symbol
>
> Duncan
>
>
> Duncan Mackay
> Department of Agronomy and Soil Science
> University of New England
> Armidale NSW 2351
> Email: home: mackay at northnet.com.au
> -------- Original Message --------
> Subject: Specifying point symbol fill colour in lattice xyplot keys
> From: Wayne Rochester <wayne.rochester at csiro.au>
> To: R-help <r-help at r-project.org>
> Date: 12/03/13 11:11
>> Dear all,
>>
>> When defining explicit keys with xyplot, I have previously used the 
>> fill parameter to set the background colour of point symbols. That's 
>> no longer working for me, and I am wondering whether it's a bug or 
>> whether I've misinterpreted the documentation and have been relying 
>> on a feature wasn't intended. If the latter, can anyone suggest the 
>> correct way to do it?
>>
>> Here's an example of what I am trying to do:
>>
>> library(lattice)
>>
>> print(xyplot(y ~ x,
>>              data=data.frame(x=1:10, y=1:10),
>>              key=list(points=list(pch=21,
>>                                   col="blue",
>>                                   cex=3,
>>                                   fill="red"))))
>>
>> Only the key is of interest here. It doesn't match the data and isn't 
>> meant to.
>>
>> On R 2.15.2 and lattice 0.20-10 the circle in the key has a blue 
>> outline and a red fill colour. On R 2.15.3 and lattice 0.20-13 the 
>> fill is transparent (or white).
>>
>> The source code for draw.key looks like it is sill trying to support 
>> the fill option. I have been able to confirm the old behaviour with 
>> the old R and lattice versions on Ubuntu 11.10 and openSUSE 12.2. I 
>> have confirmed the new behaviour with the new versions on Ubuntu 
>> 11.10 and Windows 7.
>>
>> Many thanks,
>>
>> Wayne Rochester
>> CSIRO, Brisbane, Australia
>

-- 
Dr Wayne Rochester
Research Scientist
CSIRO Marine and Atmospheric Research
Level 1 Block B
Ecosciences Precinct
GPO Box 2583
Brisbane Qld 4001
Phone: +61 (0)7 3833 5943
Fax: +61 (0)7 3833 5501
E-mail: wayne.rochester at csiro.au
WWW: http://www.csiro.au/



More information about the R-help mailing list