[R] Histogram omitting/collapsing groups

Aren Cambre aren at arencambre.com
Sun Jan 1 16:59:48 CET 2012


On Sun, Jan 1, 2012 at 5:29 AM, peter dalgaard <pdalgd at gmail.com> wrote:
> Exactly. If what you want is a barplot, make a barplot; histograms are for continuous data.   Just remember that you may need to set the levels explicitly in case of empty groups: barplot(table(factor(x,levels=0:23))). (This is irrelevant with 100K data samples, but not with 100 of them).
>
> That being said, the fact that hist() tends to create breakpoints which coincide with data points due to discretization is arguably a bit of a design error, but it is age-old and hard to change now. One way out is to use truehist() from MASS, another is to explicitly set the breaks to intermediate values, as in hist(x, breaks=seq(-.5, 23.5, 1))

Thanks, everybody. I'll definitely switch to barplot.

As for continuous, it's all relative. Even the most continuous dataset
at a scale that looks pretty to humans may have gaps between the
values when you "zoom in" a lot.

Aren



More information about the R-help mailing list