代码之家  ›  专栏  ›  技术社区  ›  Omar

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

  •  0
  • Omar  · 技术社区  · 2 年前

    我想绘制一个二进制宽度为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()
    
    1 回复  |  直到 2 年前
        1
  •  1
  •   stefan    2 年前

    您可以通过 breaks= 的论点 geom_histogram :

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

    enter image description here