[R] Problems drawing a colored 'rug' in the Lattice 'densityplot'

Mark Dalphin mark.dalphin at peblnz.com
Wed Dec 15 23:46:04 CET 2010

Hi All,

I'm trying to add a 'rug' representation of my data to a plot created 
with densityplot(). While I can do this in the simple case, I can't do 
it properly when I include the "groups" argument. I have an example 
below. I am running a reasonably new version of R.

R version 2.12.0 Patched (2010-11-07 r53537)
Platform: i686-pc-linux-gnu (32-bit)

 [1] LC_CTYPE=en_NZ.UTF-8       LC_NUMERIC=C               LC_TIME=en_NZ.UTF-8        LC_COLLATE=en_NZ.UTF-8    
 [5] LC_MONETARY=C              LC_MESSAGES=en_NZ.UTF-8    LC_PAPER=en_NZ.UTF-8       LC_NAME=C                 

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] lattice_0.19-13

R code to show the problem:

## Setup - load package, set random seed & create fake dataset
d <- data.frame(Type=rep(LETTERS[1:4], times=250),
                Category=rep(LETTERS[22:26], times=200),
                Value=c(rnorm(500), rnorm(300, 0.5), rnorm(200, 1))

## Basic "densityplot" using 'points' to show the data
densityplot(~Value|Type, data=d)

## And I can plot a 'rug' for the simple density plot
densityplot(~Value|Type, data=d, plot.points='rug')

## Now add a "groups" selector to show sub-grouping of data by 'Category'
## Note: the data points are in color
densityplot(~Value|Type, group=Category, data=d)

## Finally, with the groups, and with a rug.
## Note: no color for the rug
densityplot(~Value|Type, group=Category, data=d, plot.points='rug')

So, I can draw a rug (which is an improvement over version 2.9.1 of R 
when I got no rug), however, the color associated with the 'group' 
doesn't seem to propagate through to the rug. Is there something I am 
doing wrong here or is this a bug? Anyone have suggestions to work 
around this?


More information about the R-help mailing list