[R] barchart but with boxes

Daisy Englert Duursma daisy.duursma at gmail.com
Tue Jun 8 04:00:47 CEST 2010


Thanks to all,

I did eventually come up with a solution which involved sub-setting
the data first into categories, making an empty plot, and then
plotting rectangles.  I really like the ggplot2 and I will use that
next time.

My ugly script is below

Thanks,
Daisy


plot(1, xlim=c(5,45),ylim=c(0,10),xlab="Year",ylab="+/- 1 \u03c3 Mean
Patch Size (ha)",axes=F,type="n")
		title(main = list("Patch Size Agreement", cex=1.4))
		axis(2)
		box()
		mtext(c(2010,2030,2050,2070),side=1,line = 1, at=c(10,20,30,40))
		position<-seq(10, 40, length.out=4 )
		xlef<-position-2.5
		xrig <-position+2.5
		
		for(i in 1:nrow(sub00)){
			min_y<-sub00$minsd_ha[i]
			max_y<-sub00$maxsd_ha[i]
			xleft<-xlef[1]
			xrigh<-xrig[1]
			rect(xleft, min_y, xrigh, max_y,border = NA,col=rgb(0, 0, 0, alpha=0.03))
		}
		
for(i in 1:nrow(sub01)){
			min_y<-sub01$minsd_ha[i]
			max_y<-sub01$maxsd_ha[i]
			xleft<-xlef[2]
			xrigh<-xrig[2]
			rect(xleft, min_y, xrigh, max_y,border = NA,col=rgb(0, 0, 0, alpha=0.03))
			}
					
		
		for(i in 1:nrow(sub02)){
			min_y<-sub02$minsd_ha[i]
			max_y<-sub02$maxsd_ha[i]
			xleft<-xlef[3]
			xrigh<-xrig[3]
			rect(xleft, min_y, xrigh, max_y,border = NA,col=rgb(0, 0, 0, alpha=0.03))
			}
			
				
		for(i in 1:nrow(sub03)){
			min_y<-sub03$minsd_ha[i]
			max_y<-sub03$maxsd_ha[i]
			xleft<-xlef[4]
			xrigh<-xrig[4]
			rect(xleft, min_y, xrigh, max_y,border = NA,col=rgb(0, 1, 0, alpha=0.03))
			}



More information about the R-help mailing list