WeiQiang.Li@seagate.com
2004-Mar-01 09:18 UTC
[R] How to plot Histogram with frequence overlaid by distribution curve
Hi, I am facing the problem that I want to plot a histogram chart set freq to true and overlay with normal or weibull or exponential distribution curve. The sample code is shown as below: >samp<-c(-8.2262,-8.2262,-8.2262,-8.20209,-8.09294,-8.07321,-8.07321, -8.07321,-8.07175,-8.04948,-8.04948,-8.04948,-8.03848,-8.03848, -8.026,-7.92517,-7.92517,-7.77218,-7.62414,-7.62414,-7.62414, -7.59027,-7.59027,-7.59027,-7.59027,-7.59027,-7.59027,-7.28924, -7.28924,-6.78729,-6.25307) >hist(samp,freq=TRUE,br=20) >curve(dnorm(x,mean=mean(samp),sd=sd(samp)),add=TRUE) In the chart created based on above command, curve scale is too small compared to the freqeunce. My question here is how to adjust the scale of distribution curve. Thanks ! Best Regards WeiQiang Li
Gabor Grothendieck
2004-Mar-01 12:12 UTC
[R] How to plot Histogram with frequence overlaid by distribution curve
histdata <- hist(samp,freq=TRUE,br=20) curve(max(histdata$count)*dnorm(x,mean=mean(samp),sd=sd(samp)),add=TRUE) --- Date: Mon, 1 Mar 2004 17:18:12 +0800 From: <WeiQiang.Li at seagate.com> To: <r-help at stat.math.ethz.ch> Subject: [R] How to plot Histogram with frequence overlaid by distribution curve Hi, I am facing the problem that I want to plot a histogram chart set freq to true and overlay with normal or weibull or exponential distribution curve. The sample code is shown as below:>samp<-c(-8.2262,-8.2262,-8.2262,-8.20209,-8.09294,-8.07321,-8.07321,-8.07321,-8.07175,-8.04948,-8.04948,-8.04948,-8.03848,-8.03848, -8.026,-7.92517,-7.92517,-7.77218,-7.62414,-7.62414,-7.62414, -7.59027,-7.59027,-7.59027,-7.59027,-7.59027,-7.59027,-7.28924, -7.28924,-6.78729,-6.25307)>hist(samp,freq=TRUE,br=20) >curve(dnorm(x,mean=mean(samp),sd=sd(samp)),add=TRUE)In the chart created based on above command, curve scale is too small compared to the freqeunce. My question here is how to adjust the scale of distribution curve. Thanks ! Best Regards WeiQiang Li
Rolf Turner
2004-Mar-01 13:43 UTC
[R] How to plot Histogram with frequence overlaid by distribution curve
In response to a posting from WeiQiang Li:> Hi, > I am facing the problem that I want to plot a histogram chart set > freq to true and overlay with normal or weibull or exponential distribution > curve. > > The sample code is shown as below: > >samp<-c(-8.2262,-8.2262,-8.2262,-8.20209,-8.09294,-8.07321,-8.07321, > -8.07321,-8.07175,-8.04948,-8.04948,-8.04948,-8.03848,-8.03848, > -8.026,-7.92517,-7.92517,-7.77218,-7.62414,-7.62414,-7.62414, > -7.59027,-7.59027,-7.59027,-7.59027,-7.59027,-7.59027,-7.28924, > -7.28924,-6.78729,-6.25307) > > >hist(samp,freq=TRUE,br=20) > >curve(dnorm(x,mean=mean(samp),sd=sd(samp)),add=TRUE) > > In the chart created based on above command, curve scale is too small > compared to the freqeunce. My question here is how to adjust the scale of > distribution curve. Thanks ! >Gabor Grothendieck wrote:> histdata <- hist(samp,freq=TRUE,br=20) > curve(max(histdata$count)*dnorm(x,mean=mean(samp),sd=sd(samp)),add=TRUE)This is a perfectly correct answer to a question that should not have been asked in the first place. What WeiQiang Li proposes to do makes no sense at all, and will simply confuse and mislead the viewer/reader. If a histogram is to be overlaid with a density curve that histogram should represent a density and hence should be plotted on the density scale --- NOT on the frequency scale. cheers, Rolf Turner rolf at math.unb.ca
Spencer Graves
2004-Mar-01 15:18 UTC
[R] How to plot Histogram with frequence overlaid by distribution curve
?truehist in library(MASS)? library(MASS) truehist(samp) x <- seq(-8.5, -6, length=51) lines(x, dnorm(x, mean(samp), sqrt(var(samp)))) This just worked for me in both S-Plus 6.2 and R 1.8.1. hope this helps. spencer graves Rolf Turner wrote:>In response to a posting from WeiQiang Li: > > > >>Hi, >>I am facing the problem that I want to plot a histogram chart set >>freq to true and overlay with normal or weibull or exponential distribution >>curve. >> >>The sample code is shown as below: >> >> >>>samp<-c(-8.2262,-8.2262,-8.2262,-8.20209,-8.09294,-8.07321,-8.07321, >>> >>> >>-8.07321,-8.07175,-8.04948,-8.04948,-8.04948,-8.03848,-8.03848, >>-8.026,-7.92517,-7.92517,-7.77218,-7.62414,-7.62414,-7.62414, >>-7.59027,-7.59027,-7.59027,-7.59027,-7.59027,-7.59027,-7.28924, >>-7.28924,-6.78729,-6.25307) >> >> >> >>>hist(samp,freq=TRUE,br=20) >>>curve(dnorm(x,mean=mean(samp),sd=sd(samp)),add=TRUE) >>> >>> >>In the chart created based on above command, curve scale is too small >>compared to the freqeunce. My question here is how to adjust the scale of >>distribution curve. Thanks ! >> >> >> > >Gabor Grothendieck wrote: > > > >>histdata <- hist(samp,freq=TRUE,br=20) >>curve(max(histdata$count)*dnorm(x,mean=mean(samp),sd=sd(samp)),add=TRUE) >> >> > >This is a perfectly correct answer to a question that should not have >been asked in the first place. What WeiQiang Li proposes to do makes >no sense at all, and will simply confuse and mislead the viewer/reader. >If a histogram is to be overlaid with a density curve that histogram >should represent a density and hence should be plotted on the density >scale --- NOT on the frequency scale. > > cheers, > > Rolf Turner > rolf at math.unb.ca > >______________________________________________ >R-help at stat.math.ethz.ch mailing list >https://www.stat.math.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > >
Rolf Turner
2004-Mar-01 20:48 UTC
[R] How to plot Histogram with frequence overlaid by distribution curve
Spencer Graves wrote:> ?truehist in library(MASS)? > > library(MASS) > truehist(samp) > x <- seq(-8.5, -6, length=51) > lines(x, dnorm(x, mean(samp), sqrt(var(samp))))> This just worked for me in both S-Plus 6.2 and R 1.8.1.What's wrong with ``hist(samp,prob=TRUE)''?> hope this helps. spencer gravesI wasn't aware that I was in need of any help. I merely made a comment on a wrong-headed question that was addressed to this list. cheers, Rolf Turner
WeiQiang.Li@seagate.com
2004-Mar-04 06:26 UTC
[R] How to plot Histogram with frequence overlaid by distribution curve
Hi, I am having a new problem that how I can set the probability scale from 0 to 1 when I using on probability scale. Sometimes I get the maximum probabilty more than 100%. Thanks! Best Regards, WeiQiang In response to a posting from WeiQiang Li:> Hi, > I am facing the problem that I want to plot a histogram chart set > freq to true and overlay with normal or weibull or exponentialdistribution> curve. > > The sample code is shown as below: > >samp<-c(-8.2262,-8.2262,-8.2262,-8.20209,-8.09294,-8.07321,-8.07321, > -8.07321,-8.07175,-8.04948,-8.04948,-8.04948,-8.03848,-8.03848, > -8.026,-7.92517,-7.92517,-7.77218,-7.62414,-7.62414,-7.62414, > -7.59027,-7.59027,-7.59027,-7.59027,-7.59027,-7.59027,-7.28924, > -7.28924,-6.78729,-6.25307) > > >hist(samp,freq=TRUE,br=20) > >curve(dnorm(x,mean=mean(samp),sd=sd(samp)),add=TRUE) > > In the chart created based on above command, curve scale is too small > compared to the freqeunce. My question here is how to adjust the scale of > distribution curve. Thanks ! >Gabor Grothendieck wrote:> histdata <- hist(samp,freq=TRUE,br=20) > curve(max(histdata$count)*dnorm(x,mean=mean(samp),sd=sd(samp)),add=TRUE)This is a perfectly correct answer to a question that should not have been asked in the first place. What WeiQiang Li proposes to do makes no sense at all, and will simply confuse and mislead the viewer/reader. If a histogram is to be overlaid with a density curve that histogram should represent a density and hence should be plotted on the density scale --- NOT on the frequency scale. cheers, Rolf Turner rolf at math.unb.ca
Rolf Turner
2004-Mar-04 11:55 UTC
[R] How to plot Histogram with frequence overlaid by distribution curve
You wrote:> I am having a new problem that how I can set the probability scale > from 0 to 1 when I using on probability scale. Sometimes I get the > maximum probabilty more than 100%.When you set prob=TRUE you get a ***density*** scale. The resulting histogram represents a probability density function (directly comparable with the normal density function you sought to superimpose) which ***integrates*** to 1. The values of a density funcion need not be less than 1; these values are not probabilities. They are probability densities. Roughly if f(x) is the p.d.f. for X then f(x) dx approx. = P(x <= X <= x + dx) I.e. f(x) dx will be less than 1, but f(x) on its own need not be. O.K.? cheers, Rolf Turner rolf at math.unb.ca