Say I have a data frame like this:
df <- data.frame(year_day = rep(1:365, 3),
year = rep(2001:2003, each = 365),
value = sin(2*pi*rep(1:365, 3)/365))
It represents some value (value) for each day of the year (year_day) between 2001 and 2003. I'd like to plot each year and use ggplot2 to do so.
ggplot(df) + geom_point(aes(year_day, value)) + facet_wrap(~year, ncol=1)
This gives me:
Great. Now, say I want to extend my plotting region a bit, so that each year includes 3 months of the preceding year and 3 months of the next year (if these data exist). This means that some data will be plotted twice. For example, the first three months of 2003 will appear in the plots for 2002 and 2003. So, I could duplicate these rows and assign them to 2002, but with year-days 366 to 485. This works, but is cludgy. Is there a more elegant solution?
