[R] Problems with segments and multiple graphs

Ott Toomet otoomet at econ.dk
Thu Dec 5 12:41:02 CET 2002


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.




More information about the R-help mailing list