【发布时间】:2019-08-06 16:17:49
【问题描述】:
在 r 中绘制直方图时,我想指定我的 bin,但我得到了一些其他的。
这是我的长度数据
pss <-
structure(list(LengthSize = c(48, 39, 94, 30, 81, 49, 44, 85,
44, 55, 45, 47, 44, 43, 42, 44, 76, 42, 65, 43, 43, 90, 105,
32, 31, 43, 36, 65, 21, 15, 113, 113, 44, 46, 94, 90, 95, 37,
25, 72, 49, 46, 48, 49, 49, 44, 50, 48, 37, 37, 55, 60, 65, 30,
22, 26, 43, 43, 43, 43, 18, 67, 110, 64, 28, 29, 38, 37, 38,
37, 38, 70, 58, 65, 55, 60, 40, 22, 68, 88, 88, 32, 44, 86, 37,
38, 67, 52, 48, 123, 50, 114, 37, 38, 39, 41, 60, 55, 50, 99,
57, 44, 45, 45, 51, 44, 45, 37, 39, 43, 43, 50, 51, 34, 42, 44,
46, 67, 67, 56, 56, 57, 56, 47, 65, 66, 43, 41, 69, 45, 114,
60, 55, 37, 88, 85, 39, 39, 46, 50, 60, 44, 77, 61, 68, 46, 114,
51, 105, 48, 95, 32, 40, 28, 42, 47, 46, 48, 50, 96, 45, 47,
118, 55, 60, 34, 118, 39, 52, 119, 40, 55, 60, 55, 59, 102, 73,
42, 78, 56, 74, 102, 88, 38, 36, 33, 34, 41, 120, 50, 46, 79,
98, 65, 40, 45, 42, 50, 61, 44)),
row.names = c(NA, 200L), class = "data.frame")
这是我在 ggplot2 中的代码。
pss %>%
ggplot(data = pss,breaks = 25,xlim = c(0,528,11), mapping = aes(x = LengthSize )) +
geom_histogram(binwidth = 10, col = "black", fill = "grey")
【问题讨论】:
-
请登录并查看您问题中的数据。眼睛不是很舒服。请适当地格式化您的帖子。最好使用
dput提供数据。使用dput(head(df,n))。 -
只需在您的
geom_histogram(binwidth = 10, bins=50, col = "black", fill = "grey")中传递bins=no_bins_you_want。尝试不同的数字,直到找到符合您需求的数字。 -
您不需要管道
pss %>%和ggplot(data = pss, etc)。只使用其中之一。 (建议:不是管道。)
标签: r