如何在R中设置直方图中的特定间隔?

问题描述 投票:0回答:1

我想绘制一个 binwidth 为 4 的直方图。我无法修复这些数据的间隔。我希望我的垃圾箱从 x = 28 开始,从那里开始间隔为 4。例如 - 28-32、32-36、36-40 等。如何设置特定间隔并固定直方图的起始值?

crushing_strength <- c(40,37.9,29,31.7,39.3,40.7,42.7,40,50.3,
                                  33.8,39.3,42.1,45.5,41.4,47.6,38.6,35.9,
                                  41.4,44.1,40,40.7,42.1,38.6,36.5,40.7)
test_no <- seq(1:25)

data_example <- data.frame(test_no,crushing_strength)


ggplot(data_example, aes(x = crushing_strength))+
  geom_histogram(binwidth=4)+
  scale_x_continuous()
r histogram intervals bins
1个回答
0
投票

您可以通过

breaks=
geom_histogram
参数指定所需的中断:

library(ggplot2)

ggplot(data_example, aes(x = crushing_strength)) +
  geom_histogram(breaks = seq(28, 52, 4)) +
  scale_x_continuous()

© www.soinside.com 2019 - 2024. All rights reserved.