[R] Panel plots for means of cyclical observations

Kieran kroberts012 at gmail.com
Fri Jan 15 13:16:11 CET 2016


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.



More information about the R-help mailing list