Skip to content

Problems with segments and multiple graphs

3 messages · Ross Darnell, Ott Toomet, Uwe Ligges

#
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

#
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.
doesn't make any difference.

Can I draw a (one) line that crosses both graphs?

Thanks 

Ross Darnell
#
Hi,

there are perhaps problems with par(mfg) and coordinate system (at
least on my R 1.5.1 on RH 7.2).  But you may do

  y <- rnorm(3000)
  par(mfrow=c(2,1))
  plot(y,type="l")
  segments(1000,min(y),1000,max(y), col=2)
  plot(cumsum(y),type="l")
  segments(1000,min(cumsum(y)),1000,max(cumsum(y)), col=3)

i.e. plot and draw segment on upper graph, and thereafter do the same
on the lower.  Plot starts a new graph, but segements works on the
previous one.

Perhaps it helps.

Ott

 | From: Ross Darnell <r.darnell at shrs.uq.edu.au>
 | Date: 05 Dec 2002 14:46:20 +1000
 | 
 | 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.
#
Ross Darnell wrote:
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.
Yes. A simple but rather ugly solution:

  par(xpd = NA)
  abline(v = 1000)

Uwe Ligges