Lattice xyplot with text under x-axis
Still on this question, I'm having problems with displaying the text when
repeated values are present. For example:
library(lattice)
year<-c(2001,2002,2003,2001,2002,2003,2001,2002,2003,2001,2002,2003)
fac<-c("arts","arts","arts","arts","arts","arts","sci","sci","sci","sci","sci","sci")
type<-c("est","est","est","early","early","early","est","est","est","early","early","early")
staff<-c(95,98,99,32,31,36,57,52,55,24,23,26)
part<-c(32,31,33,15,16,14,40,41,43,15,17,19)
df1<-data.frame(year,fac,type, staff,part)
n.val.text<-paste("n = ", df1$staff, sep = "")
xyplot(part~year | type+fac, as.table=TRUE, type="o",
between=list(x=1,y=1),xlab="",ylab="",
scales = list(relation = "free", x = list(at = year, labels =paste(year,
n.val.text, sep = "\n"))))
This attempts to place all the values of "staff" under each year. Is there a
any way to correct this?
http://www.nabble.com/file/p23103168/lattice_xyplot_with_axis_text.png
Deepayan Sarkar wrote:
On Wed, Apr 15, 2009 at 8:59 AM, kate.m <katherine797 at gmail.com> wrote:
Hi All,
I have a data set which I need to plot and show the values of one of the
variables as a second x-axis.
library(lattice)
year<-c(2001,2002,2003,2004,2005,2006)
fac<-c("arts","arts","arts","sci","sci","sci")
staff<-c(95,98,99,32,31,36)
part<-c(32,31,33,15,16,14)
df1<-data.frame(year,fac,staff,part)
xyplot(part~year, type="o", xlab="", ylab="")
n.val.text<-paste("n = ", df1$staff, sep = "")
mtext(n.val.text, side = 1, line = 3, at = axTicks(1), cex = 0.9)
This works OK.
Not really...
The problem comes in when I plot the data in panels. xyplot(part~year | fac, as.table=TRUE, type="o", between=list(x=1,y=1), xlab="", ylab="", scales=list(x=list(alternating=3),y=list(alternating=3), relation="free")) The mtext code doesn't work anymore. I think it needs some sort of panel function (panel.groups?) which would tell it to show the appropriate values of "staff" under their respective "year" for each "fac" and each panel.
Something like
xyplot(part~year | fac, as.table=TRUE, type="o", between=list(x=1,y=1),
scales = list(relation = "free", x = list(at = year, labels =
paste(year, n.val.text, sep = "\n"))))
-Deepayan
______________________________________________ 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.
View this message in context: http://www.nabble.com/Lattice-xyplot-with-text-under-x-axis-tp23061842p23103168.html Sent from the R help mailing list archive at Nabble.com.