[R] two ecdf in the same figure

Joshua Wiley jwiley.psych at gmail.com
Sun Sep 25 00:57:14 CEST 2011


Or just ask let the second plot know to add it to the existing plot:

set.seed(2)
plot(ecdf(rnorm(50)))
plot(ecdf(rnorm(50,,2)), add = TRUE, pch = 2)
legend(-2.9, .95, legend = c("First ECDF", "Second ECDF"), pch = c(16, 2))

note the limits are set by the first plot, so watch out for that.  You
may want to explicitly set xlim to avoid problems.

set.seed(2)
plot(ecdf(rnorm(50)), xlim = c(-4.5, 4.5))
plot(ecdf(rnorm(50,,2)), add = TRUE, pch = 2)
legend(-4.2, .95, legend = c("First ECDF", "Second ECDF"), pch = c(16, 2))

Cheers,

Josh


On Sat, Sep 24, 2011 at 10:04 AM, R. Michael Weylandt
<michael.weylandt at gmail.com> wrote:
> What version of R are you using?
>
> x = ecdf(rnorm(50)); y = ecdf(rnorm(50))
>
> plot(x); lines(y, col=2)
>
> works for me on R 2.13.1. Specifically, there is a lines.stepfun method
> (albeit non-visible) which handles this.
>
> Michael
>
> On Sat, Sep 24, 2011 at 12:23 PM, Adel ESSAFI <adel.safi at imag.fr> wrote:
>
>> Hello,
>>
>> is ot possible to draw two ecdf of vectors (say s1 and s2) on the same
>> figire with R.
>>
>> plot function draws a new plot and there is no function like points or
>> lines
>> to draw a second ecdf on the figure.
>>
>> Regards
>>
>>
>> --
>> *PhD candidate in Computer Science
>> Address
>> 3 avenue lamine, cité ezzahra, Sousse 4000
>> Tunisia
>> tel: +216 97 246 706
>> fax: +216 71 391 166*
>>
>>        [[alternative HTML version deleted]]
>>
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>>
>
>        [[alternative HTML version deleted]]
>
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>



-- 
Joshua Wiley
Ph.D. Student, Health Psychology
Programmer Analyst II, ATS Statistical Consulting Group
University of California, Los Angeles
https://joshuawiley.com/



More information about the R-help mailing list