[R] superimpose density line over hist
Romain Francois
francoisromain at free.fr
Tue Dec 13 15:40:59 CET 2005
Le 13.12.2005 14:23, Albert Vilella a écrit :
>Hi all,
>
>I'm trying to superimpose a rchisq density line over a histogram with
>something like:
>
>hist(alnlength)
>lines(density(rchisq(length(alnlength), 4)),col="red")
>
>But the rchisq line won't appear anywhere,
>
>Anyone knows what I am missing here?
>
>Thanks in advance,
>
> Albert.
>
>
Hi Albert,
A few comments :
- your code should be reproductible, otherwise it is useless. (that
recommandation is on the posting guide)
- that question is a top ten question on that list, go to the archive
and you will find answers. (also posting guide)
BTW, it should be a FAQ and what about an example of overlaying in hist
help page ?
- then if you want to superimpose an histogram and a density curve, they
should be on the same scale, it is not the case since you missed the
argument freq in your hist call, it should be :
R> hist(alnlength, freq=FALSE)
- Why do you simulate points to draw the density line ? Give a shot at :
R> curve(dchisq, df=4, col="red")
- That might interrest you :
http://addictedtor.free.fr/graphiques/search.php?q=hist
Romain
--
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 |
+---------------------------------------------------------------+
More information about the R-help
mailing list