【问题标题】:How to change binwidth of a histogram with the layer function如何使用图层功能更改直方图的 binwidth
【发布时间】:2017-03-13 14:20:20
【问题描述】:

我尝试从 rlnorm(100) 创建的 100 个随机数中使用 ggplot2 的层函数制作直方图。

到目前为止,这是我的代码;

library(ggplot2)
verdeling <- rlnorm(100)
verdeling <- as.data.frame(verdeling)
verdeling$num <- verdeling$verdeling
joost$verdeling <- verdeling$num
    p <- ggplot(data = verdeling, mapping = aes(x = num))


    p2 <- p + layer(
      geom = "bar",
      stat = "bin",
      position = "stack",



    )
    p2

如何更改直方图的 binwidth? 通常我在没有图层功能的情况下制作直方图,它就像 binwidth = x 一样简单。

提前致谢。

鲁本

【问题讨论】:

    标签: r ggplot2 histogram layer


    【解决方案1】:

    使用layer 函数时,将附加参数作为列表传递给params

    p2 <- p + layer(
        geom = "bar",
        stat = "bin",
        position = "stack",
        # Add binwidth = x as a list to params
        params = list(binwidth = x)
    )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-04
      • 1970-01-01
      • 1970-01-01
      • 2012-10-09
      • 1970-01-01
      • 2020-08-28
      相关资源
      最近更新 更多