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

I have a couple of cumulative empirical density functions that I would like to build on top of each other to illustrate the differences in the two curves. As pointed out in the previous question , the ECDF drawing function is just plot(Ecdf()) And when I read the beautiful manual page, I decided that I could build several ECDFs on top of each other using something like the following:

 require( Hmisc ) set.seed(3) g <- c(rep(1, 20), rep(2, 20)) Ecdf(c( rnorm(20), rnorm(20)), group=g) 

However, my curves sometimes overlap a bit and it can be difficult to determine what exactly, like the example above that this graph creates:

enter image description here

I would really like the color of these two CDFs to be different. However, I cannot figure out how to do this. Any tips?

+8
r plot ecdf
source share
2 answers

If memory works, I have done this in the past. As far as I remember, you had to trick him, since Ecdf() so damned. I think in help(ecdf) he hints that this is just a plot step, so you can evaluate two or more ecdfs, build one, and then annotate through lines() .

Change It turns out it's as simple as

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

since the col= argument is clearly indicated on the help page. But I also found some scripts where I used plot.stepfun() explicitly.

+12
source share

You can add each curve one at a time (each with its own style), for example

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

All Articles