我正在尝试H.Wickham在R book中的钻石数据集。在x =克拉的钻石的默认geom_histogram中,bin宽度为0.5,但bin 1从-0.25开始,即使克拉的最低值为0.2。为什么会这样呢?附加图片和上下文代码。谁能帮忙解释一下。谢谢。
##geom_histogram
geom_histogram(mapping=aes(x = carat),binwidth = 0.5)
summary(diamonds)
##dplyr to get count of cut[![enter image description here][1]][1]
diamonds %>%
count(cut_width(carat,0.5))
这有帮助吗?
在p1中,第一个容器位于0的中心。但是您希望容器的左侧从0-p2开始。因此,您必须告诉ggplot移动垃圾箱。您可以使用文档中讨论的boundary
or或center
参数来执行此操作。
library(ggplot2)
library(patchwork)
##geom_histogram
p1 <-
ggplot(diamonds)+
geom_histogram(mapping=aes(x = carat), binwidth = 0.5)+
ggtitle("p1 bars centred on bin boundaries")
p2 <-
ggplot(diamonds)+
geom_histogram(mapping=aes(x = carat), binwidth = 0.5, boundary = 0)+
ggtitle("p2 bars between bin boundaries")
p1+p2
由reprex软件包(v0.3.0)创建于2020-05-25
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句