[R] overlap cdf plots and add colors and etc

Peter Ehlers ehlers at ucalgary.ca
Thu Nov 25 15:22:56 CET 2010


On 2010-11-24 22:24, Roslina Zakaria wrote:
> Hi Jorge,
>
> I tried but still it does not work.  Thank you for your time.
>
Jorge's code works perfectly well.

If you prefer lines() over plot(...., add = TRUE),
then use lines():

  plot( ecdf(rnorm(15, sd=3)), verticals=TRUE, col="black")
  lines(ecdf(rnorm(11, sd=3)), verticals=TRUE, col="red")
  legend("topright", legend = c("observed","fitted"),
        col = c("black","red"), pch=c(NA,NA), lty = c(1, 1),
        lwd=c(3,3),bty="n", pt.cex=2)

(Note that "topright" is probably the worst choice you
can make. And why set pt.cex when you don't have points??)

The key thing is that you can't specify your two
colours in the first plot() call. At that point,
R has no idea that you want to add to the plot.
(I understand that Greg Snow is working on a
mind-reading package, but so far it can probably
read only his mind, not yours.)

Here is a (very brief) reminder of how to post:

1. Use an informative subject line.
    You've done that. Good!

2. *Never* use the phrase "it does not work".
    That is meaningless.
    Be specific about your problem.

3. Provide *reproducible* code.
    We don't have your 'datobs' or 'gam_sum_gen'.

4. Try to make the code *minimal*.
    It's not likely that anyone cares what labels you
    use for your axes/title (unless that's the problem).
    And nobody wants to see reams of data; use rnorm(),
    etc, or built-in data if possible.

5. Figure out how to set your mail program to send
    plain text.

I know the above (and more) is in the posting guide,
but it seems that nobody wants to read that quite
brief document.

Peter Ehlers

>
> ________________________________
> From: Jorge Ivan Velez<jorgeivanvelez at gmail.com>
>
> Cc: r-help at r-project.org
> Sent: Thu, November 25, 2010 4:46:37 PM
> Subject: Re: [R] overlap cdf plots and add colors and etc
>
> Hi Roslina,
>
>
> Try
>
> par(mar=c(4,4,2,1.2),oma=c(0,0,0,0),xaxs="i", yaxs="i")
> plot(ecdf(rnorm(100)))
> plot(ecdf(rnorm(100)), add = TRUE, col = 2)
>
> HTH,
> Jorge
>
>
> On Thu, Nov 25, 2010 at 12:18 AM, Roslina Zakaria<>  wrote:
>
> Hi r-users,
>>
>> I would like to overlap 2 ecdf plots.
>>
>> I tried this below and it gives me two plots of ecdf but just both just in
>> black.
>>
>> par(mar=c(4,4,2,1.2),oma=c(0,0,0,0),xaxs="i", yaxs="i")
>> plot(ecdf(datobs))
>> lines(ecdf(gam_sum_gen))
>>
>> Then I try to add colors etc and also the legend but fail.
>>
>> par(mar=c(4,4,2,1.2),oma=c(0,0,0,0),xaxs="i", yaxs="i")
>> plot(ecdf(datobs),main ="CDF of the sum for winter
>> season-Hume",cex.axis=1.2,xlab="Rainfall (mm)", pch =
>> pch,verticals=TRUE,col=c("black","red"), lty=c(1,1),ylab="Cumulative
>> probability", xlim=c(0,800),lwd=1)
>> lines(ecdf(gam_sum_gen))
>> legend("topright", legend = c("observed","fitted"),
>>         col = c("black","red"), pch=c(NA,NA), lty = c(1, 1),
>>         lwd=c(3,3),bty="n", pt.cex=2)
>> box()
>>
>> I'm not sure why it doesn't show up at all.
>>
>> Thank you for any help given.
>>
>>
>>
>>         [[alternative HTML version deleted]]
>>
>>



More information about the R-help mailing list