[R] segplot (latticeExtra)

Sebastian P. Luque spluque at gmail.com
Tue May 25 05:07:31 CEST 2010


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.


Cheers,

-- 
Seb



More information about the R-help mailing list