R:具有自定义中断和恒定宽度的直方图

R: Histogram with both custom breaks and constant width

我有一些偏斜的数据,想创建一个带有自定义间隔的直方图,但希望它实际上看起来可读且具有恒定的 bin 宽度(这会偏离 x 轴的比例,但这没关系) .有谁知道如何在 ggplot/R 中执行此操作?

这是我不想要的,但我不知道如何让中断不覆盖宽度参数:

library(ggplot2)
test_data = rep(c(1,2,3,4,5,8,9,14,20,42,98,101,175), c(50,40,30,20,10,6,6,7,9,5,6,4,1))
buckets = c(-.5,.5,1.5,2.5,3.5,4.5,5.5,10.5,99.5,200)
q1 = qplot(test_data,geom="histogram",breaks=buckets)
print(q1)

不是我想要的直方图:(

按照 ulfelder 的建议,使用 cut():

library(ggplot2)
test_data = rep(c(1,2,3,4,5,8,9,14,20,42,98,101,175),
                c(50,40,30,20,10,6,6,7,9,5,6,4,1))
buckets = c(-.5,.5,1.5,2.5,3.5,4.5,5.5,10.5,99.5,200)
q1 = qplot(cut(test_data, buckets), geom="histogram")
print(q1)