【问题标题】:Add density curve to percentage histogram [duplicate]将密度曲线添加到百分比直方图[重复]
【发布时间】:2021-11-02 04:59:39
【问题描述】:

我有一个 Y 轴百分比的直方图:

    df <- data.frame(V1 = rnorm(100))
    ggplot(df, aes(x = V1)) +  
  geom_histogram(aes(y = 100*(..count..)/sum(..count..)))+geom_density()

我尝试使用 geom_density() 添加密度曲线,但它的百分比比例似乎错误。我该如何解决这个问题?

【问题讨论】:

    标签: r ggplot2


    【解决方案1】:

    你可以使用..density..

    代码

    df %>% 
      ggplot(aes(x = V1)) +  
      geom_histogram(aes(y = ..density..))+
      geom_density()
    

    输出

    【讨论】:

    • 如何保留 Y 轴以保持百分比?
    猜你喜欢
    • 2021-02-04
    • 2016-09-16
    • 2021-03-14
    • 1970-01-01
    相关资源
    最近更新 更多