Problems with segments and multiple graphs
Ross Darnell wrote:
I would like to create a page of two graphs (2 rows by 1 col) and then draw vertical lines (segments?) on both graphs from the minimum values to the corresponding maximum value. So I have tried #
y <- rnorm(3000) par(mfrow=c(2,1)) plot(y,type="l") plot(cumsum(y),type="l") segments(1000,min(cumsum(y)),1000,max(cumsum(y))) par(mfg=c(1,1)) segments(1000,min(y),1000,max(y)) y <- rnorm(3000)
The segment looks fine on the bottom graph but I get a small vertical line on the top graph. The max(y) value looks OK but the min(y) looks like the second largest value.
ymin <- min(y) ymax <- max(y) segments(1000,ymin,1000,ymax)
doesn't make any difference.
OK. The par settings won't be resetted completely, but you can do so manually: y <- rnorm(3000) par(mfrow=c(2,1)) plot(y,type="l") rpar <- par() # remember par settings plot(cumsum(y),type="l") segments(1000,min(cumsum(y)),1000,max(cumsum(y))) par(rpar) # restore the settings to draw the line par(mfg=c(1,1)) segments(1000,min(y),1000,max(y), col="red") In your case it is simpler to complete each plot before stepping to the next one.
Can I draw a (one) line that crosses both graphs?
Yes. A simple but rather ugly solution: par(xpd = NA) abline(v = 1000) Uwe Ligges