[R] specifying scales in lattice xyplot makes the lines disappear?

Christopher W Ryan cryan at binghamton.edu
Tue May 10 22:10:03 CEST 2011


I have a dataframe concerning manner of death from death certificates,
from 2005 to 2009 inclusive, with the following structure:

> str(MannerYoung.plot.data)
'data.frame':   245 obs. of  4 variables:
 $ year         : Factor w/ 5 levels "2005","2006",..: 1 2 3 4 5 1 2 3 4 5 ...
 $ manner       : Factor w/ 7 levels "Accident","Homicide",..: 1 1 1 1
1 2 2 2 2 2 ...
 $ new.age.group: Factor w/ 7 levels "1 to 4","5 to 9",..: 1 1 1 1 1 1
1 1 1 1 ...
 $ Freq         : int  [omitted from this post]...
>

new.age.group categorizes age of death in 5-year age bands.

The following makes a nice lattice scatterplot, with a panel for each
age-band, year on the horizontal axis,and frequency on the veritcal
axis.

xyplot(Freq~year | new.age.group, groups=manner,
data=MannerYoung.plot.data, type="l",  auto.key =
list(text=levels(MannerYoung.plot.data$manner), lines=TRUE,
points=FALSE, space = "top"),
layout=c(length(levels(MannerYoung.plot.data$new.age.group)),1))

Except that the year tick labels overlap each other. I thought I would
try to label only every other tick, using scales(), like this:

xyplot(Freq~year | new.age.group, groups=manner,
data=MannerYoung.plot.data, type="l",
scales=list(x=list(at=c(2005,2007,2009),
labels=c("2005","2007","2009"))), auto.key =
list(text=levels(MannerYoung.plot.data$manner), lines=TRUE,
points=FALSE, space = "top"),
layout=c(length(levels(MannerYoung.plot.data$new.age.group)),1))

This draws the panels, vertical axis, horizontal axes, with the
odd-numbered years, everything as desired, except that there are no
lines in the panels--no actual content.

I suppose I could decrease the font size for the year labels, using
cex(), and that cured the overlap, but I wanted to understand
scales().

Where am I going wrong?

Thanks.

--Chris Ryan



More information about the R-help mailing list