给定数据框:
d = structure(list(bin_start = 1:12,
bin_count = c(12892838L, 1921261L, 438219L, 126650L, 41285L,
15948L, 6754L, 3274L, 1750L, 992L, 703L, 503L)),
.Names = c("bin_start", "bin_count"),
class = "data.frame",
row.names = c(NA, 12L))
我可以用
stat="identity"
建立直方图:ggplot(d) +
geom_histogram(aes(x=bin_start, y=bin_count), stat="identity",
colour="black", fill="white") +
scale_x_continuous(breaks=1:12)
看起来像这样:
对长尾不满意我限制了 x 比例(相当于
xlim=c(1,6)
):ggplot(d) +
geom_histogram(aes(x=bin_start, y=bin_count), stat="identity", colour="black", fill="white") +
scale_x_continuous(breaks=1:12, limits=c(1,6))
但我得到边界点
x=1
和 x=6
消失:请注意,y 轴仍然像边界点一样缩放,属于情节美学。这是一个功能还是一个错误?
最佳答案
功能的副作用。由于您自己对数据进行了分箱,因此您可能需要离散比例和 x
的因子。 :
ggplot(d) +
geom_histogram(aes(x=factor(bin_start), y=bin_count), stat="identity", colour="black", fill="white") +
scale_x_discrete(limit=as.character(1:6))
关于r - 为什么 xlim 会切断连续尺度的边界值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18211170/