[R] max-min plot

Uwe Ligges ligges at statistik.uni-dortmund.de
Sat Sep 29 17:42:26 CEST 2001


Antonio Olinto wrote:
> 
> Dear R-list members,
> 
> Thanks for those who replied my e-mail (Frank, Martin and Uwe) on "max-min
> plot".
> 
> Following Uwe's suggestion I did my job as showed bellow. This example
> should be useful for begginers (like myself).
> 
> Thanks,
> 
> Antonio
> 
> ------------------------------
> 
>     Year  Value     Z
> 1  1994 0.15062 Zm
> 2  1995 0.20622 Zm
> 3  1996 0.20373 Zm
> 4  1997 0.22153 Zm
> 5  1998 0.23426 Zm
> 6  1999 0.23533 Zm
> 7  1994 0.14075 Z-
> 8  1995 0.17051 Z-
> 9  1996 0.16989 Z-
> 10 1997 0.18350 Z-
> 11 1998 0.21494 Z-
> 12 1999 0.19841 Z-
> 13 1994 0.16048 Z+
> 14 1995 0.24193 Z+
> 15 1996 0.23757 Z+
> 16 1997 0.25956 Z+
> 17 1998 0.25357 Z+
> 18 1999 0.27225 Z+
> 
> > plot(Year,Value,type="n",xlab="year",ylab="Z")
> > points(Year[c(1:6)],Value[c(1:6)],pch=3)
> > segments(Year[c(7)],Value[c(7)],Year[c(13)],Value[c(13)])
> > segments(Year[c(8)],Value[c(8)],Year[c(14)],Value[c(14)])

In principle, the plot(), points(), segments() was indeed my suggestion.
Now let me suggest a simplification.
It is really not necessary to call segments for each line to plot, see
?segments.

 # Check what line is mean, max, min
 Zm <- which(Z == "Zm")
 Zp <- which(Z == "Z+")
 Zq <- which(Z == "Z-")
 # ... assuming the year is sorted ...
 plot(Year, Value, type="n", xlab="year", ylab="Z")
 points(Year[Zm], Value[Zm], pch=3)
 segments(Year[Zq], Value[Zq], Year[Zp], Value[Zp])

Uwe Ligges
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list