How to Plot a Pre-Binned Histogram In R

后端 未结 2 571
北海茫月
北海茫月 2021-01-11 18:09

I have a pre-binned frequency table for a rather large dataset. That is, a single column vector of bins and a single column vector of counts associated with those bins. I\'d

2条回答
  •  悲&欢浪女
    2021-01-11 18:23

    The new HistogramTools package on CRAN has a number of useful functions for doing exactly this. In your example, if you want to merge three adjacent buckets together at each point in the histogram to produce a new histogram with 1/3rd as many buckets, you could use the MergeBuckets function.

    install.packages("HistogramTools")
    library(HistogramTools)
    h <- hist(rexp(1000), breaks=60)
    plot(MergeBuckets(h, adj.buckets=3))
    

    Alternatively, you can also specify a list of the new breakpoints you want explicitly, rather than telling MergeBuckets() to always merge the same number of adjacent buckets. enter image description here

提交回复
热议问题