Skip to content

highlighted a certain time period on multiple plots

3 messages · Ye Lin, Adams, Jean, R. Michael Weylandt

#
Hey All,

I have a dataset like this:

DatedayVar1Var2Var3Obs1/1/2013Tue23411/2/2013Wed23521/3/2013Thu24631/4/2013
Fri24741/5/2013Sat24.5851/6/2013Sun24.9961/7/2013Mon25.31071/8/2013Tue25.711
81/9/2013Wed26.11291/10/2013Thu26.513101/11/2013Fri26.914111/12/2013Sat27.3
15121/13/2013Sun27.716131/14/2013Mon28.117141/15/2013Tue28.518151/16/2013Wed
28.919161/17/2013Thu29.320171/18/2013Fri29.721181/19/2013Sat210.12219
1/20/2013Sun210.523201/21/2013Mon210.924211/22/2013Tue211.325221/23/2013Wed2
11.726231/24/2013Thu212.127241/25/2013Fri212.528251/26/2013Sat212.92926
1/27/2013Sun213.330271/28/2013Mon213.731281/29/2013Tue214.132291/30/2013Wed2
14.533301/31/2013Thu214.93431
Here is the code I use to plot:

par(mar=c(10, 0.5, 0.5, 0.5))
par(mfrow=c(3,1))
plot(Var1~Obs,data=dat,xaxt="n",xlab="")
plot(Var2~Obs,data=dat,xaxt="n",xlab="")
plot(Var3~Obs,data=dat,xaxt="n",xlab="")
axis(1,at=dat$Obs,label=dat$Date)
mtext(1,text="Date",line=2.5)
axis(1,at=dat$Obs,label=dat$day,line=4)
mtext(1,text="Day of week",line=7)

How can I remove the extra white space between plots and emphasize time
periods=weekend with dashed area?? I have attached original output and
ideal output I am looking for.

Any suggestion to emphasize/highlight weekend periods is really appreciate!

Thanks!
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 16505 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20130605/accd27cd/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image (1).png
Type: image/png
Size: 67240 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20130605/accd27cd/attachment-0001.png>
#
On Thu, Jun 6, 2013 at 6:43 AM, Ye Lin <yelin at lbl.gov> wrote:
Take a look at my "xtsExtra" package off of R-forge:

## Using your data as Jean arranged it.
library(xtsExtra)

dat2 <- xts(dat[,c(3,4,5)], as.Date(dat[,1], format = "%m/%d/%Y"))

plot(dat2, yax.loc = "left")

and look at

example(plot.xts)

for how to do shading / lines as desired.

Cheers,
MW