[R] Stair steps plotting

Göran Broström gb at stat.umu.se
Tue Mar 11 21:59:02 CET 2003


Consider the following two ways of stair steps plotting:

plo <- function(ty = 2, steps = 200){
  old.par <- par(mfrow = c(2, 1))
  x <- seq(1, 100, length = steps)
  y <- seq(1, 10, length = steps)
  plot(x, y, type = "s", lty = ty, main = "Stair steps")

  x <- rep(x, each = 2)[-1]
  y <- rep(y, each = 2)[-2*steps]
  plot(x, y, type = "l", lty = ty, main = "Line steps")
  par(old.par)
}

This shows a problem with 'type = "s"' combined with "lty = "; the lines 
look solid no matter what lty is set to, if the steps are small enough. 
Is this intentional, and if so, why? This bit me when I tried to plot 
empirical cdfs with the 'type = "s"' method; some curves were impossible 
to distinguish.

Btw, I checked 'plot.survfit', and it uses the second method, probably of 
this reason.

Göran
---
 Göran Broström                    tel: +46 90 786 5223
 Department of Statistics          fax: +46 90 786 6614
 Umeå University                   http://www.stat.umu.se/egna/gb/
 SE-90187 Umeå, Sweden             e-mail: gb at stat.umu.se



More information about the R-help mailing list