Hello I'd like to plot a histogram of some data composed of real numbers. The bin width I'm using is ~ 0.01, which results in high values in the y axis, so that the area under each bar corresponds to the probability of the data in that range. Is is possible to plot points whose y coordinate correspond to that probability, instead of plotting the histogram bars? In other words, instead of having a bar of width 0.01 and height, say, 80, I'd like to have a single point at y = 0.8. I know I could use the values returned from hist() and calculate that manually, but maybe there's a better way to do that. I've been using prop.table() to plot these "histograms" for integer numbers, but now I need binning and I'm not sure what is the best way to proceed. Thanks in advance, Andre
Hi Andre, On May 19, 2008, at 4:28 PM, Andre Nathan wrote:> Hello > > I'd like to plot a histogram of some data composed of real numbers. > The > bin width I'm using is ~ 0.01, which results in high values in the y > axis, so that the area under each bar corresponds to the > probability of > the data in that range. > > Is is possible to plot points whose y coordinate correspond to that > probability, instead of plotting the histogram bars? In other words, > instead of having a bar of width 0.01 and height, say, 80, I'd like to > have a single point at y = 0.8. > > I know I could use the values returned from hist() and calculate that > manually, but maybe there's a better way to do that. I've been using > prop.table() to plot these "histograms" for integer numbers, but now I > need binning and I'm not sure what is the best way to proceed.I would use ?cut to create a factor, followed with the usual prop.table (+ table) you have been using. Unless you didn't want to have control over the precise binning?> Thanks in advance, > AndreHaris Skiadas Department of Mathematics and Computer Science Hanover College
> Is is possible to plot points whose y coordinate correspond to that > probability, instead of plotting the histogram bars? In other words, > instead of having a bar of width 0.01 and height, say, 80, I'd like to > have a single point at y = 0.8.Very easily with ggplot2: install.packages("ggplot2") library(ggplot2) qplot(carat, data=diamonds, stat="bin", geom="point") qplot(carat, data=diamonds, stat="bin", geom="point", binwidth=0.01) # or with a line qplot(carat, data=diamonds, stat="bin", geom="line") # oh and by default the y axis gives count, to give probalilites use qplot(carat, ..density.., data=diamonds, stat="bin", geom="point") Hadley -- http://had.co.nz/