An embedded and charset-unspecified text was scrubbed... Name: not available Url: https://stat.ethz.ch/pipermail/r-help/attachments/20060810/494ed830/attachment.pl
hist() and bar spacing
3 messages · Amelie LESCROEL, Uwe Ligges, Jim Lemon
Amelie LESCROEL wrote:
Hello, Could someone explain to me why I get so different histograms, in terms of bar spacing, depending on the number of counts entered ? (see example below)
test <- c(0,1,1,1,1,0,0,0,0,0,2,3,2,2,2,3,3,4,5,6,7,5,4,3,4,2,2)
hist(test)
I obtain this kind of histogram (what I actually want), i.e. large bars with no space between them x xx xxx xxxx xxxxx xxxxxx xxxxxxx xxxxxxxxx xxxxxxxxxx Entering:
test <-
c(3,1,2,1,1,1,2,1,1,2,2,2,0,1,1,1,3,0,0,2,5,2,0,0,1,6,0,1,1,4,0,0,2,1,0,1,3, 0,0,0,3,2,1,3,6,3,1,0,1,0,1,0,1,0,0,4,1,3,2,7,5,1,0,0,1,2,0,2,0,2,0,2,1,1,3, 1,3,0,2,1,3,1,1,0,1,7,2,1,2,2,2,1,2,5,1,2,2,2,1,1,4,2,0,4,1,1,1,5,1,0,2,5,2, 1,1,1,1,2,1,1,1,1,4,2,1,3,1,1,2,4,2,1,1,1,1,1,1,1,1,1,4,1,0,2,2,5,1,4,0,1,2, 2,2,2,1,2,1,3,5,2,0,0,2,0,0,0,0,1,1,2,2,1,1,2,1,0,1,0,2,1,3,0,0,0,1,3,1,3,1, 0,3,1,2,0,1,1,1,3,4,4,2,1,1,1,2,1,2,2,5,1,1,1,1,1,2,0,1,3,1,1,2,3,1,1,2,0,0, 2,0,1,1,1,1,1,1,1,1,1,1,5,3,1,1,1,0,0,1,0,1,1,0,0,1,2,0,0,0,2,3,1,1,1,2,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,1,1,2,0,1,0,0,0,1,3,0,1,3,1,2,1,1,2,1,1,3,1,1,1,0,0, 1,1,1,1,1,1,1,1,4,1,3,3,1,2,1,2,3,4,1,0,2,2,1,2,1,2,3,0,0,2,3,2,4,1,0,1,1,0, 1,3,2,3,3,1,3,1,0,2,1,1,1,1,1,1,3,0,0,1,1,1,1,1,1,3,1,3,3,0,1,2,1,2,3,1,2,1, 2,2,2,1,1,1,1,0,2,2,1,2,2,2,1,1,2,2,1,1,1,2,2,1,1,1)
You data follows a *discrete* distribution, hence a barplot seems to be more appropriate here: barplot(table(testtest)) Uwe Ligges
hist(test)
I obtain a strange histogram with the first 2 bars grouped together and then thin bars (not occupying the entire bin width) separated by spaces. x x x xx x xx x x xx x x x xx x x x x xx x x x x xx x x x x x xx x x x x x x xx x x x x x x x x I suspect that it?s causing me some troubles to fit my data to a probability density function. Using:
plot(density(test))
I got a ?wave-shaped? density line, with the line going down to zero between each bar. And I wouldn?t expect the density line to go down between each integer? or surely there is something that I don?t understand! Thanks for your help, Am?lie Lescro?l [[alternative HTML version deleted]] ------------------------------------------------------------------------
______________________________________________ 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 and provide commented, minimal, self-contained, reproducible code.
Amelie LESCROEL wrote:
... I obtain this kind of histogram (what I actually want), i.e. large bars with no space between them ... I obtain a strange histogram with the first 2 bars grouped together and then thin bars (not occupying the entire bin width) separated by spaces. ... I suspect that it?s causing me some troubles to fit my data to a probability density function. Using:
Hi Amelie, Them's the breaks. Try this: hist(test,breaks=-1:7) and you should get what you want. Jim