Create a filled line graph with R

I used the code below to create a presentation-quality graph of data on how individual’s activation level (measured as electrodermal activity) changes over time during a group-based task. (Click on the image to enlarge.)


<br />quartz(width=16,height=8,type="pdf",file="indiv_eda_z.pdf",dpi=600)<br />par(xpd=TRUE)<br />par(family="Tahoma", bg="white", mar=c(3,3,3,3), mgp=c(1,1,1))<br /><br />ylim <- c(-1.5, 1.5)<br />xlim <- c(-540, 2700)<br />x <- aggsub$task_time<br />y <- aggsub$eda_z<br />ylo <- rep(min(y), length(y))<br />plot(x,y, type="n", ylim=ylim, axes=FALSE, ylab="Electrodermal Activity", xlab="Time (in minutes)", xlim=xlim, col="dark green")<br /><br />xpos <- seq(-540, 2700, 180)<br />lab <- seq(-9, 45, 3)<br />axis(1, at=xpos, labels=lab, cex =1.5, lwd=.5, lty=3, tck=1, col="dark gray", pos=-1.5, col.axis="dark gray")<br /><br />ypos <- seq(-1.5, 1.5, .5)<br />axis(2, at=ypos , labels=ypos, cex =1.5, las=2, tck=1, lwd=.5, lty=3, col="dark gray", pos=-540, col.axis="dark gray")<br /><br />zerox <- -540:2700<br />zeroy <- rep(0, length(zerox))<br />lines(zerox, zeroy, lty=1, lwd=2, col="red")<br /><br /><br />lines(x,y, lwd=2.5,col="dark green")<br />xx <- c(x, rev(x))<br />yy <- c(ylo, rev(y))   <br />polygon(xx, yy, col="light green", border=FALSE)<br /><br />sessionstart <- min(x)<br />taskstart <- 0<br />taskend <- 1800<br />recordend <- 1920<br />sessionend <- max(x)<br /><br />polygon(c(sessionstart, sessionstart, taskstart, taskstart), c(1.5, min(y), min(y), 1.5), col="#0015FF25", border=FALSE)<br />text(-270, 1.25, "Pre-Task Survey", col="dark blue")<br /><br /><br />#polygon(c(taskstart, taskstart, taskend, taskend), c(1.5, min(y), min(y), 1.5), col="#EAFF0025", border=FALSE)<br />text(900, 1.25, "Group Members Work to Develop Recruitment Video", col="dark green")<br /><br /><br />polygon(c(taskend, taskend, recordend, recordend), c(1.5, min(y), min(y), 1.5), col="#FA050535", border=FALSE)<br />text(recordend-(recordend-taskend)/2, 1.25, "RecordnVideo", col="red")<br /><br /><br />polygon(c(recordend, recordend, sessionend, sessionend), c(1.5, min(y), min(y), 1.5), col="#0015FF25", border=FALSE)<br />text(sessionend-(sessionend-recordend)/2, 1.25, "Post-Task Survey", col="dark blue")<br /><br />dev.off()<br />