也许您正在寻找以下breaks
论点geom_histogram
:
# create some fake data
id <- sample(1:100000, 10000, rep=T)
visits <- sample(1:1200,10000, rep=T)
#merge to create a dataframe
df <- data.frame(cbind(id,visits))
#plot the data
require(ggplot2)
ggplot(df, aes(x=visits)) +
geom_histogram(breaks=c(seq(0, 200, by=10), max(visits)), position = "identity") +
coord_cartesian(xlim=c(0,210))
这看起来像这样(需要注意的是,这里的假数据看起来很糟糕,并且轴也需要调整以匹配中断):
编辑:
也许其他人可以在这里权衡:
# create breaks and labels
brks <- c(seq(0, 200, by=10), max(visits))
lbls <- c(as.character(seq(0, 190, by=10)), "200+", "")
# true
length(brks)==length(lbls)
# hmmm
ggplot(df, aes(x=visits)) +
geom_histogram(breaks=brks, position = "identity") +
coord_cartesian(xlim=c(0,220)) +
scale_x_continuous(labels=lbls)
情节错误:
Error in scale_labels.continuous(scale) :
Breaks and labels are different lengths
看起来像这样,但那是 8 个月前修复的。