Skip to content
Prev 6480 / 15274 Next

Seasonal plot of daily data

On Mon, Aug 2, 2010 at 11:28 AM, SNV Krishna <snvk4u at gmail.com> wrote:
Try this:

library(zoo)

# input data
DF <- data.frame(date = as.Date(0:999), value = 1:1000)

# create columns for year and
# julian day (1st, 2nd, ... day of the year)

DF$year <- cut(DF$date, "year")
DF$jul <- ave(DF$value, DF$year, FUN = seq_along)

# split into 1 col per year. year is col 2. index is col 3.
z <- read.zoo(DF[-1], index = 3, split = 2)

# plot - screen = 1 causes all columns to be in same frame
colors <- 1:ncol(z)
plot(z, screen = 1, col = colors)
legend("bottomright", leg = substr(levels(DF$year), 1, 4), fill = colors)