Quantcast

Re: superimpose density line over hist

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: superimpose density line over hist

Martin Maechler
>>>>> "Romain" == Romain Francois <[hidden email]>
>>>>>     on Tue, 13 Dec 2005 15:40:59 +0100 writes:

          ........

    Romain> A few comments :
    Romain> - your code should be reproductible, otherwise it is useless. (that
    Romain> recommandation is on the posting guide)

    Romain> - that question is a top ten question on that list, go to the archive
    Romain> and you will find answers. (also posting guide)
    Romain> BTW, it should be a FAQ and what about an example of overlaying in hist
    Romain> help page ?

What about the following one --- do also note the comments though!

set.seed(14)
x <- rchisq(100, df = 4)

## Comparing data with a model distribution should be done with qqplot()!
qqplot(x, qchisq(ppoints(x), df = 4)); abline(0,1, col = 2, lty = 2)

## if you really insist on using hist() ... :
hist(x, prob = TRUE, ylim = c(0, 0.2))
curve(dchisq(x, df = 4), col = 2, lty = 2, lwd = 2, add = TRUE)



    Romain> - then if you want to superimpose an histogram and a density curve, they
    Romain> should be on the same scale, it is not the case since you missed the
    Romain> argument freq in your hist call, it should be :

    R> hist(alnlength, freq=FALSE)

    Romain> - Why do you simulate points to draw the density line ? Give a shot at :

    R> curve(dchisq, df=4, col="red")

    ...........

Martin Maechler, ETH Zurich

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: superimpose density line over hist

Romain François
Le 14.12.2005 11:54, Martin Maechler a écrit :

>>>>>>"Romain" == Romain Francois <[hidden email]>
>>>>>>    on Tue, 13 Dec 2005 15:40:59 +0100 writes:
>>>>>>            
>>>>>>
>
>  ........
>
>    Romain> A few comments :
>    Romain> - your code should be reproductible, otherwise it is useless. (that
>    Romain> recommandation is on the posting guide)
>
>    Romain> - that question is a top ten question on that list, go to the archive
>    Romain> and you will find answers. (also posting guide)
>    Romain> BTW, it should be a FAQ and what about an example of overlaying in hist
>    Romain> help page ?
>
>What about the following one --- do also note the comments though!
>  
>
Great !

>set.seed(14)
>x <- rchisq(100, df = 4)
>
>## Comparing data with a model distribution should be done with qqplot()!
>qqplot(x, qchisq(ppoints(x), df = 4)); abline(0,1, col = 2, lty = 2)
>
>## if you really insist on using hist() ... :
>hist(x, prob = TRUE, ylim = c(0, 0.2))
>curve(dchisq(x, df = 4), col = 2, lty = 2, lwd = 2, add = TRUE)
>
>  
>
I agree with you about qqplot, but a lot of people like that kind of
hist-density overlay ...

--
visit the R Graph Gallery : http://addictedtor.free.fr/graphiques
mixmod 1.7 is released : http://www-math.univ-fcomte.fr/mixmod/index.php
+---------------------------------------------------------------+
| Romain FRANCOIS - http://francoisromain.free.fr               |
| Doctorant INRIA Futurs / EDF                                  |
+---------------------------------------------------------------+

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Loading...