rplotecdf

How to plot multiple ECDF's on one plot in different colors in R


I am trying to plot 4 ecdf functions on one plot but can't seem to figure out the proper syntax.

If I have 4 functions "A, B, C, D" what would be the proper syntax in R to get them to be plotted on the same chart with different colors. Thanks!


Solution

  • The package latticeExtra provides the function ecdfplot.

    library(lattice)
    library(latticeExtra)
    
    set.seed(42)
    vals <- data.frame(r1=rnorm(100)*0.5,
                       r2=rnorm(100),
                       r3=rnorm(100)*2)
    
    ecdfplot(~ r1 + r2 + r3, data=vals, auto.key=list(space='right')
    

    ecdfplot with legend