【问题标题】:What is ggplot - geom_histogram - boundary doingggplot - geom_histogram - 边界在做什么
【发布时间】:2020-05-24 16:48:41
【问题描述】:

使用moderndive 包和碗数据集比较不同的表示方法。设置边界似乎改变了数据分布的位置我在函数使用中缺少什么?

vs <- bowl %>%
      rep_sample_n(size = 50, reps = 10000) %>%
      group_by(replicate) %>%
      summarise(num_red = sum(color=="red")) %>%
      mutate(prop_red = num_red/ 50) %>%
      mutate(prop_white  = 1 - prop_red)

c1 <-ggplot(vs, aes(x=prop_red)) + 
      geom_histogram(color =  "white", binwidth = 0.025) + labs(title="c1")

c2 <-ggplot(vs, aes(x=prop_red)) + 
      geom_histogram(color =  "white", binwidth = 0.025, boundary = 0.4)

grid.arrange(c1,c2,nrow = 1)

【问题讨论】:

标签: r ggplot2 histogram


【解决方案1】:

boundary 参数是一个 bin 位置说明符。您在 c2 图上强制在 0.4 处分档,而 c1 图会根据 0.025 分档宽度自动分配分档。

由于您的分布是折扣的(尽管在使用 0.025 绑定宽度时无法理解这一点),因此您的 bin 位置会对直方图计数产生很大影响。请参阅下面的第三个图,将以下内容添加到您的代码中:

c3 <-ggplot(vs, aes(x=prop_red)) + 
     geom_histogram(color =  "white", binwidth = 0.0125)

added third plot with smaller binwidth to show discontinuity

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多