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

From: Christopher W Ryan <cryan_at_binghamton.edu>
Date: Tue, 10 May 2011 16:10:03 -0400


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



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. Received on Tue 10 May 2011 - 20:12:59 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 10 May 2011 - 21:40:06 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive