[R] Panel plots for means of cyclical observations
Richard M. Heiberger
rmh at temple.edu
Fri Jan 15 17:06:34 CET 2016
## I think the root problem is that you allowed the levels of month to
## continuing with your example
##You need to take control of the levels with a statement like
z$month <- factor(z$month, levels=monthsOfYear)
## now you can write something like
z$month.parity <- factor(z$month,
levels=unlist(matrix(levels(z$month), 6, 2, byrow=TRUE)))
##  "January" "March" "May" "July" "September" "November"
##  "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
On Fri, Jan 15, 2016 at 7:16 AM, Kieran <kroberts012 at 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),
> 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 at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help