Re: [R] Add function to histogram?

From: Romain Francois <francoisromain_at_free.fr>
Date: Wed 21 Sep 2005 - 20:11:40 EST

Le 21.09.2005 10:37, Romain Francois a écrit :

>Le 21.09.2005 10:00, Peter Wolf a écrit :
>
>
>
>>Robert Lundqvist wrote:
>>
>>
>>
>>
>>>Is there any neat way to add a curve (frequency function or the like) to a
>>>histogram or other plots? I haven't found one yet...
>>>
>>>Robert
>>>
>>>
>>>
>>>
>>???
>>
>>dat<-rnorm(100)
>>hist(dat,prob=TRUE)
>>x<-seq(-3.5,3.5,length=100)
>>y<-dnorm(x)
>>lines(x,y)
>>
>>have a look at: http://cran.at.r-project.org/doc/manuals/R-intro.pdf
>>
>>Peter Wolf
>>
>>
>>
>>
>For a frequency polygon, try to work around that piece of code,
>following Peter's notations :
>
>dat <- rnorm(100)
>h <- hist(dat,prob=TRUE, border="gray", col="gray90")
>diffBreaks <- diff(h$breaks)[1]
>xx <- c(h$mids[1]-diffBreaks, h$mids, tail(h$mids,1)+diffBreaks)
>yy <- c(0, h$density, 0)
>lines(xx, yy, lwd=2)
>
>However, you might prefer (and that's probably wise) the kernel density
>estimator : density() that other people suggested.
>
>Romain
>
>
>
I just added frequency polygon to the R Graph Gallery, see : http://addictedtor.free.fr/graphiques/RGraphGallery.php?graph=101

Regards,

Romain

-- 
visit the R Graph Gallery : http://addictedtor.free.fr/graphiques
~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~
~~~~~~      Romain FRANCOIS - http://addictedtor.free.fr         ~~~~~~
~~~~        Etudiant  ISUP - CS3 - Industrie et Services           ~~~~
~~                http://www.isup.cicrp.jussieu.fr/                  ~~
~~~~           Stagiaire INRIA Futurs - Equipe SELECT              ~~~~
~~~~~~   http://www.inria.fr/recherche/equipes/select.fr.html    ~~~~~~
~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Wed Sep 21 20:31:43 2005