[R] segplot (latticeExtra)

Felix Andrews felix at nfrac.org
Tue May 25 13:40:54 CEST 2010


On 25 May 2010 13:07, Sebastian P. Luque <spluque at gmail.com> wrote:
> Hi,
>
> I'm having a bit of trouble with 'scales="free"' in the segplot()
> function of latticeExtra.  Say we need panels for each year, showing
> only those counties that are represented in each one:
>
> ---<--------------------cut here---------------start------------------->---
> library(latticeExtra)
> data(USCancerRates)
> uscr.w <- subset(USCancerRates, state == "Washington")
> uscr.w$year <- gl(4, 10, length=nrow(uscr.w), labels=format(seq(2001, 2004)))
>
> segplot(reorder(factor(county), rate.male) ~ LCL95.male + UCL95.male | year,
>        data=uscr.w, scales="free")
> ---<--------------------cut here---------------end--------------------->---
>
> This still plots all levels of county in every panel.  Based on a
> similar need for dotplot in another thread, the following looked
> promising, but gives empty panels:
>
> ---<--------------------cut here---------------start------------------->---
> segplot(reorder(factor(county), rate.male) ~ LCL95.male + UCL95.male | year,
>        data=uscr.w, scales="free",
>        prepanel=function(x, y, z, ...) {
>            zz <- z[, drop=TRUE]
>            list(sort(unique(zz)))
>        },
>        panel=function(x, y, z, ...) {
>            zz <- z[, drop=TRUE]
>            panel.segplot(x, y, zz, ...)
>        })
> ---<--------------------cut here---------------end--------------------->---
>
> Is it possible to have only counties for the particular panel (year) in
> these plots?  Thanks.


In this type of plot (it is based on levelplot() internally) you need
to apply the subscripts inside the prepanel and panel functions.


segplot(reorder(factor(county), rate.male) ~ LCL95.male + UCL95.male | year,
       data=uscr.w, scales = list(y = list(relation = "free", rot = 0)),
       prepanel=function(x, y, z, subscripts, ...) {
           ans <- prepanel.segplot(x, y, z, subscripts = subscripts, ...)
           zz <- z[subscripts, drop=TRUE]
           ans$ylim = levels(zz)
           ans
       },
       panel=function(x, y, z, subscripts, ...) {
           zz <- z[subscripts, drop=TRUE]
           panel.segplot(x[subscripts], y[subscripts], zz,
               subscripts = TRUE, ...)
       })



>
>
> Cheers,
>
> --
> Seb
>
> ______________________________________________
> 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.
>



-- 
Felix Andrews / 安福立
Postdoctoral Fellow
Integrated Catchment Assessment and Management (iCAM) Centre
Fenner School of Environment and Society [Bldg 48a]
The Australian National University
Canberra ACT 0200 Australia
M: +61 410 400 963
T: + 61 2 6125 4670
E: felix.andrews at anu.edu.au
CRICOS Provider No. 00120C
-- 
http://www.neurofractal.org/felix/



More information about the R-help mailing list