pedrosmarques at portugalmail.pt
2007-Dec-15 15:13 UTC
[R] Using boxplot in a daily time series
Hi all, I'm trying to plot my daily time series, with 3650 observations( 10 years), with boxplot but I want 12 boxes, one for each month, can anyone help me doing that. Best regards
From your post it is not clear how the data are organized. Supposing they are in a data frame you could use the ~ sintax. For example: timeColumn=as.Date("01-01-1970") + 1:500 timeSeries=rnorm(500) df=data.frame(time=timeColumn, index=timeSeries)> > head(df) > time index > 1 1-01-20 -0.6382554 > 2 1-01-21 -2.0346649 > 3 1-01-22 -0.4900213 > 4 1-01-23 0.7311806 > 5 1-01-24 0.9386528 > 6 1-01-25 0.7868129boxplot(index~months(time), data=df) Perhaps you would order the 12 boxes according to the months: monthColumn=ordered(months(df$time), levels= c("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December")) boxplot(df$index~monthColumn) domenico pedrosmarques at portugalmail.pt wrote:> Hi all, > > I'm trying to plot my daily time series, with 3650 observations( 10 years), with boxplot but I want 12 boxes, one for each month, can anyone help me doing that. > > Best regards > > ______________________________________________ > R-help at r-project.org mailing list > 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. > >
On Saturday 15 December 2007 07:13:34 am pedrosmarques at portugalmail.pt wrote:> Hi all, > > I'm trying to plot my daily time series, with 3650 observations( 10 years), > with boxplot but I want 12 boxes, one for each month, can anyone help me > doing that. > > Best regards >Sure, there are several approaches to this, but in general thinking about your data in terms of 'grouping' factors can be helpful example: # 1 year's worth of dates: d <- strptime(1:365, format="%j") # some simulated data x <- rlnorm(365) # combine them into a DF dx <- data.frame(date=d, value=x) # plot the data, note that x-axis is in dates: plot(dx) # now generate a grouping factor. how about months: dx$month <- format(dx$date, format="%B") # box and whisker plot for data *grouped* by month boxplot(value ~ month, data=dx, las=3) cheers, Dylan