The boxplot below is close to what I would like, but needs some clean up. 
I've been unable to address the following:
1) How can I use the full extent of the plot space (there is white space on
either side of the data)?
2) How can I reduce the # of month labels (e.g. every 3rd month Jan Mar
Jun...) but still keep them staggered?
3) The year labels at the top of the plot have been positioned using the
following line

>mtext(year.observed,3,at=seq(3,99,by=12),padj=-1)

I would prefer to position the label using the actual value contained in the
date column of the data.frame (which is a "date" variable type).  Fixing the
position as I have doesn't seem...pure?

4) The grid is meant to partition the data from year to year and was
generated using

>grid(nx=9,ny=0,col="gray60",lty=1)

but it is clearly off.  Is there a way to draw the grid lines exactly
between december and January?  I wasn't sure how much code I should include,
so here it all is: (images follow)

my.dat<-read.table("C:/Eric/Programs/UtilityProgram_Summarize_UNSAT_Zone_Results_8Class/Process_UZF_Output/bin/R_Data_fracETSat_US.txt",header=TRUE,sep="\t")
attach(my.dat)
dates<-strptime(as.character(my.dat$date),"%m/%e/%Y")
my.dat=my.dat[,2:5]
my.dat=data.frame(date=dates,my.dat)
detach(my.dat)
daterange=c(as.POSIXlt(min(my.dat$date)),as.POSIXlt(max(my.dat$date)))
rm(dates)
attach(my.dat)

cropped=subset(my.dat,Classification==5)
natveg=subset(my.dat,Classification==7)

> cropped[c(1,2,3),]  #Example data
          date Cell_ID Classification WT_Depth Frac_ET_Satsfd
94  1999-04-08    4395              5 1.572998      0.7596927
95  1999-04-08    4396              5 1.923096      0.7588058
101 1999-04-08    4403              5 2.290039      0.7911426

month.year <- function (x) {12*(as.POSIXlt(x)$year-99)+as.POSIXlt(x)$mon+1}
month<-month.year(my.dat$date)
months<-month.name
cropped.month<-month.year(cropped$date)
mean.cropped.frac<-tapply(cropped$Frac_ET_Satsfd,cropped.month,mean)
month.observed <- numeric(length(mean.cropped.frac))
for(i in
1:length(mean.cropped.frac)){month.observed[i]=as.numeric(names(mean.cropped.frac[i]))%%12}
month.observed[month.observed==0]<-12  #make the decembers 12 instead of 0
month.names<-months[as.numeric(month.observed)]
month.names<-substr(month.names,1,3)

year.vector<-function (x) {as.POSIXlt(x)$year+1900}
cropped.year<-year.vector(cropped$date)
mean.cropped.frac.yr<-tapply(cropped$Frac_ET_Satsfd,cropped.year,mean)
year.observed<-numeric(length(mean.cropped.frac.yr))
for(i in
1:length(mean.cropped.frac.yr)){year.observed[i]=as.numeric(names(mean.cropped.frac.yr[i]))}

boxplot(Frac_ET_Satsfd~month.year(cropped$date),data=cropped,col="lightblue",outline=F,
     range=0.00000001,ylim=c(0,1),xaxt="n")
axis(1,at=1:103,labels=F)
mtext(month.names,1,at=1:103,line=rep(c(1,2),2))
mtext(year.observed,3,at=seq(3,99,by=12),padj=-1)
grid(nx=9,ny=0,col="gray60",lty=1)

http://n4.nabble.com/file/n1476343/timeSeriesMessy.jpg 

Thanks, Eric
-- 
View this message in context: 
http://n4.nabble.com/boxplot-label-cleanup-tp1476343p1476343.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help@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.

Reply via email to