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
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?
You're using 'year' as a factor, but thinking about it as a numeric.
Use at=c(1,3,5) in your scales list.
But I would have expected the lines to plot and the axis labels
not to be visible. Are you telling the whole story?
_Minimal reproducible_ code is always a good thing.
Peter Ehlers