[R] hist(x, ...) with normal distribution curve

Romain Francois francoisromain at free.fr
Mon Sep 26 14:59:34 CEST 2005


Le 25.09.2005 14:34, Knut Krueger a écrit :

>.
>I am looking for a histogram or box plot with the adding  normal 
>distribution  curve
>I think that must be possible, but I am not able to find out how to do.
>
>
>
>Regards Knut
>  
>
Hi Knut,

There are a lot of ways to do that, let x be your data (assume x ~ 
N(mu=2,sd=.4))
R> x <- rnorm(200, mean=2, sd=.4)

** With the traditionnal graphics system, do :
R> hist(x, prob=T)
R> curve(dnorm, col=2, mean=mean(x), sd=sd(x))

** With lattice :
R> histogram(~x,
  panel = function(x,...){
    panel.histogram(x,...)
    panel.mathdensity(dmath = dnorm, col = "red",
                                args = list(mean=mean(x),sd=sd(x)))
   },
  type="density")

Then, have a look at :
http://addictedtor.free.fr/graphiques/search.php?q=hist

And also have a nice day....

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    ~~~~~~
~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~




More information about the R-help mailing list