. 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
hist(x, ...) with normal distribution curve
10 messages · Knut Krueger, PIKAL Petr, Peter Dalgaard +2 more
An embedded and charset-unspecified text was scrubbed... Name: not available Url: https://stat.ethz.ch/pipermail/r-help/attachments/20050925/e827f644/attachment.pl
Romain Francois schrieb:
Do you want that : h<-hist(x,breaks=10,freq = TRUE) xfit<-seq(min(x),max(x),length=40) yfit<-dnorm(xfit,mean=mean(x),sd=sd(x)) lines(xfit,yfit * 150 * (h$breaks[2]-h$breaks[1]))
Right thats what I want ... but does it make sense to fit the line with a try and error multipier (150) Is there no way to compute the frequency and the distribution line with standardised function? I used SPSS with the data from x<-5+rnorm(150) Hit the graph-histogramm menue choosed: display normal curve and got the result: http://biostatistic.de/temp/spss1.jpg - just as easy as possible So, they have any standardised function. maybe it does not make sence, but i am not able to see why there is such a esay to use function in SPSS but not in R Maybe anybody is able to explane whiy and my intention: As a previous computer scientist I am trying to find a way to eleminate SPSS an use R Sure there is a big lack of my statistic knowledge - but the often the SPSS user have similar lack but it is easy to click and view instead to try the similar steps in R But if I am not able to find the steps in R for the common .. "SPSS-clicks" , I will never be able to suggest R in the institute to the people with mor statistical knowledge but no knowledge about computer science ... and command line interpreter Regards Knut -- Viele Gr????e Knut Kr??ger
Reitpark Einthal
Leitung: 1 Tierarzt, 1 Berufsreiter
Homepage http://www.einthal.de
Eine fachgerechte Betreuung rund um die Uhr.
I've got a comlaint about the signature in the last post. I answered form another computer and there is the automatic signature of our second business. On this place is also a part of the equine resarch program in progress. I did not realize that there was the siganture below. Sorry for that. Regards Knut
Hi answered hundered times.
Dear R people: I would like to superimpose a normal curve on a histogram.
x<-rnorm(150) h<-hist(x,breaks=15) xhist<-c(min(h$breaks),h$breaks) yhist<-c(0,h$density,0) xfit<-seq(min(x),max(x),length=40) yfit<-dnorm(xfit,mean=mean(x),sd=sd(x)) plot(xhist,yhist,type="s",ylim=c(0,max(yhist,yfit))) lines(xfit,yfit) Bill above is e.g. Bill Simpson's answer from 2001. Found from R-site search ***histogram density normal***. HTH Petr
On 25 Sep 2005 at 14:34, Knut Krueger wrote:
. 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
______________________________________________ R-help at 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
Petr Pikal petr.pikal at precheza.cz
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 ~~~~~~ ~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~
Knut Krueger <Knut.Krueger at usa.com> writes:
Petr Pikal schrieb:
Hi answered hundered times.
Dear R people: I would like to superimpose a normal curve on a histogram.
x<-rnorm(150) h<-hist(x,breaks=15) xhist<-c(min(h$breaks),h$breaks) yhist<-c(0,h$density,0) xfit<-seq(min(x),max(x),length=40) yfit<-dnorm(xfit,mean=mean(x),sd=sd(x)) plot(xhist,yhist,type="s",ylim=c(0,max(yhist,yfit))) lines(xfit,yfit) Bill above is e.g. Bill Simpson's answer from 2001. Found from R-site search ***histogram density normal***.
Ok If I merge both of your answers I get the graph like in SPSS but the ylab is density instead frequency:
Many people consider that a feature, since histograms are supposed to be density estimates....
and I do not have the clicks in SPSS to redo the same graph :-( I hav only the Data file and the SPSS plot. x<-5+rnorm(150) h<-hist(x,breaks=10,freq = TRUE) #I need this histogramm with... xfit<-seq(min(x),max(x),length=40) yfit<-dnorm(xfit,mean=mean(x),sd=sd(x)) lines(xfit,yfit) h<-hist(x,breaks=10,prob=T) xfit<-seq(min(x),max(x),length=40) yfit<-dnorm(xfit,mean=mean(x),sd=sd(x)) # ... this line lines(xfit,yfit)
Er, something got duplicated in there? Anyways, if you want the normal curve blown up to the scale of counts/bin, just multiply yfit by the number of observations times the bin width. To find the bin width take, e.g. diff(h$mids[1:2]). If they're not all equal, then you're in deeper trouble.
O__ ---- Peter Dalgaard ??ster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
Le 25.09.2005 17:30, Knut Krueger a ??crit :
Petr Pikal schrieb:
Hi answered hundered times.
Dear R people:
I would like to superimpose a normal curve on a histogram.
x<-rnorm(150) h<-hist(x,breaks=15) xhist<-c(min(h$breaks),h$breaks) yhist<-c(0,h$density,0) xfit<-seq(min(x),max(x),length=40) yfit<-dnorm(xfit,mean=mean(x),sd=sd(x)) plot(xhist,yhist,type="s",ylim=c(0,max(yhist,yfit))) lines(xfit,yfit) Bill above is e.g. Bill Simpson's answer from 2001. Found from R-site search ***histogram density normal***.
Ok If I merge both of your answers I get the graph like in SPSS but the ylab is density instead frequency: and I do not have the clicks in SPSS to redo the same graph :-( I hav only the Data file and the SPSS plot. x<-5+rnorm(150) h<-hist(x,breaks=10,freq = TRUE) #I need this histogramm with... xfit<-seq(min(x),max(x),length=40) yfit<-dnorm(xfit,mean=mean(x),sd=sd(x)) lines(xfit,yfit) h<-hist(x,breaks=10,prob=T) xfit<-seq(min(x),max(x),length=40) yfit<-dnorm(xfit,mean=mean(x),sd=sd(x)) # ... this line lines(xfit,yfit) Thanks Knut
Ok then. what you are trying to do doesn't make any sense to me. (( That does not make much sense (for me) to have the density curve on the same scale than frequencies )) Do you want that : x<-5+rnorm(150) h<-hist(x,breaks=10,freq = TRUE) xfit<-seq(min(x),max(x),length=40) yfit<-dnorm(xfit,mean=mean(x),sd=sd(x)) lines(xfit,yfit * 150 * (h$breaks[2]-h$breaks[1])) ?
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 ~~~~~~ ~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~
Knut Krueger wrote:
. 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
______________________________________________ R-help at 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
*There are a lot of answers to add a histogram.
Here is a simple way to add a tiny boxplot to a plot / histogram
x<-rexp(100)
hist(x)
boxplot(x,axes=F,add=T,horizontal=T,
at=par()$usr[3]+diff(par()$usr[3:4])*.017,
boxwex=0.02*diff(par()$usr[3:4]),pch=8)
Peter Wolf
*
Le 27.09.2005 10:32, Peter Wolf a ??crit :
Knut Krueger wrote:
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
*There are a lot of answers to add a histogram.
Here is a simple way to add a tiny boxplot to a plot / histogram
x<-rexp(100)
hist(x)
boxplot(x,axes=F,add=T,horizontal=T,
at=par()$usr[3]+diff(par()$usr[3:4])*.017,
boxwex=0.02*diff(par()$usr[3:4]),pch=8)
Peter Wolf
The tufte axes, described there : http://www.cl.cam.ac.uk/users/sjm217/projects/graphics/ may be of interrest here. What about making it a possibility for all plots ? For example using : R> par(xaxt='tufte') R> plot(rnorm(200), rnorm(200)) would produce a scatterplot with the tufte axes 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 ~~~~~~ ~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~