R: Plotting one ECDF on top of another in different colors

If memory serves, I have done this in the past. As I recall, you needed to trick it as Ecdf() is so darn paramterised. I think in help(ecdf) it hints that it is just a plot of stepfunctions, so you could estimate two or more ecdfs, plot one and then annotate via lines().

Edit Turns out it is as easy as

  R> Ecdf(c(rnorm(20), rnorm(20)), group=g, col=c('blue', 'orange'))

as the help page clearly states the col= argument. But I have also found some scriptlets where I used plot.stepfun() explicitly.


You can add each curve one at a time (each with its own style), e.g.

Ecdf(rnorm(20), lwd = 2)
Ecdf(rnorm(20),add = TRUE, col = 'red', lty = 1)

Tags:

Plot

R

Ecdf