[R] Panel plots for means of cyclical observations
Duncan Mackay
dulcalma at bigpond.com
Sun Jan 17 02:09:30 CET 2016
Hi
Continuing on from the data.frame code for z that you supplied
Using the data without summarizing first
z$mth = format(date "%m")
z$mth = format(date, "%m")
xyplot(rainfall ~ as.numeric(mth), z,
groups = yr,
type = "l",
auto.key = T,
scales = list(x = list(at = 1:12,
labels = month.abb,
rot = 60)),
panel = panel.superpose,
panel.groups = function(x,y, ...){
panel.average(x,y, fun = mean, horizontal = FALSE,
...)
}
) ## xyplot
You may want to look into the zoo package as it has several date grouping
functions.
untested
z.tom <- aggregate(rainfall ~ year +month, z, mean, na.rm = T)
xyplot(rainfall ~ month, z.tom, groups = year,
scales = ... ,
panel = panel.superpose)
Regards
Duncan
Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mackay at northnet.com.au
-----Original Message-----
From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of Kieran
Sent: Friday, 15 January 2016 22:16
To: R-help at r-project.org
Subject: [R] Panel plots for means of cyclical observations
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 at 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.
More information about the R-help
mailing list