[R] how to draw multiple vertical bands

Jim Lemon jim at bitwrit.com.au
Thu Apr 15 12:06:23 CEST 2010


On 04/15/2010 12:36 AM, senne wrote:
> hi R gurus
>
> I saw some graphs with vertical band like this one:
>
> http://pragcap.com/wp-content/uploads/2010/04/GS.png
>
> how to draw the blue band in R, can't find any clue to do this,any ideas?
>
Hi senne,
The rect function in base graphics can do the job. First do the plot 
with type="n" (i.e. no plotting), then display your rectangles:

xylim<-par("usr")
rect.left<-as.Date(seq(paste(rep(c("Dec","Mar","Jun","Sep"),length.out=10),
  c("07","08","08","08","08","09","09","09","09","10"),sep="-")))
rect.right<-rect.left+10
rect(rect.left,xylim[3],rect.right,xylim[4],col="lightblue",border="lightblue")

then draw the line and text labels.

Warning - untested

Jim



More information about the R-help mailing list