## Kieran, ## I think the root problem is that you allowed the levels of month to be alphabetical.
## continuing with your example ##You need to take control of the levels with a statement like levels(z$month) z$month <- factor(z$month, levels=monthsOfYear) levels(z$month) ## now you can write something like z$month.parity <- factor(z$month, levels=unlist(matrix(levels(z$month), 6, 2, byrow=TRUE))) levels(z$month.parity) ## [1] "January" "March" "May" "July" "September" "November" ## [7] "February" "April" "June" "August" "October" "December" xyplot(rainfall ~ date | month, layout=c(2, 6), data=z) xyplot(rainfall ~ date | month.parity, layout=c(6, 2), data=z) ## I hope the modifications to deal with your summary measures will be straightforward. ## Rich On Fri, Jan 15, 2016 at 7:16 AM, Kieran <kroberts...@gmail.com> wrote: > I want to create a panel plot using xyplot of a line graph whose > x-axis is months of the year and y-axis is the average rainfall in a > given month over the 6 years the data spans. > > There should be two levels in this panel plot: odd and even months. > > Creating this plot without splitting it into levels is quite > straightforward (creating a for loop to compute a vector of averages) > but the approach is not useful if you want to split the plots into > different levels. > > Here is the code: > > dfmt <- "%d/%m/%Y" > date <- seq(as.Date("01/01/2010", dfmt), as.Date("31/12/2015", dfmt), > "day") > month <- months(date) > rainfall <- runif(2191, 0, 150) > monthsOfYear <- c("January", "February", "March", "April", > "May", "June", "July", "August", "September", "October", > "November", "December") > > parity <- match(month, monthsOfYear) %% 2 > # even parity = 0, odd parity = 1 > > z <- data.frame(rainfall, date, month, parity) > > The problem with using xyplot( y ~ x | f, data=z .. ) is the x and y I > want to plot are not columns in z but rather some kind of statistical > summary of columns. > > ______________________________________________ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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. ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.