【问题标题】:Overlay histogram with multiple density curves for generalized pareto distribution用于广义帕累托分布的具有多条密度曲线的叠加直方图
【发布时间】:2021-08-21 02:59:48
【问题描述】:

我想为广义帕累托分布绘制具有多条密度曲线的叠加直方图。如您所见,密度曲线不清晰可见。他们有什么办法说清楚吗?谢谢。

library(eva)
data(lowestoft)
data = as.vector(lowestoft)

d1 = dgpd(data, 0,  31.38105, 10.15003)
d2 = dgpd(data, 0, 2.9431553, 0.6778055)
d3 = dgpd(data,0, 5.413916, 17.162103)
d4 = dgpd(data,0, 43.18705, 13.98005)


N = length(data)
allden = c(d1, d2, d3, d4)
settings = c(rep('d1', N), rep('d2', N), 
             rep('d3', N), rep('d4', N))


mydata = data.frame(x= rep(data, 4), allden = allden, Methods = settings)

ggplot(mydata, aes(x)) +
  geom_histogram(aes(y = stat(density)), binwidth = 1, fill = "grey", color = "black")+
  geom_line(aes(x = x, y=allden, color = Methods)) 

【问题讨论】:

    标签: r ggplot2 histogram density-plot


    【解决方案1】:

    您可以做的一件事是像这样为geom_line 添加一个单独的缩放 y 轴

    library(eva)
    data(lowestoft)
    data = as.vector(lowestoft)
    
    d1 = dgpd(data, 0,  31.38105, 10.15003)
    d2 = dgpd(data, 0, 2.9431553, 0.6778055)
    d3 = dgpd(data,0, 5.413916, 17.162103)
    d4 = dgpd(data,0, 43.18705, 13.98005)
    
    
    N = length(data)
    allden = c(d1, d2, d3, d4)
    settings = c(rep('d1', N), rep('d2', N), 
                 rep('d3', N), rep('d4', N))
    
    
    mydata = data.frame(x= rep(data, 4), allden = allden, Methods = settings)
    
    coef <- 8
    ggplot(mydata, aes(x,allden)) +
      geom_histogram(aes(y = stat(density)), binwidth = 1, fill = "grey", color = "black") +
      geom_line(aes(x = x, y=allden*coef, color = Methods)) +
      scale_y_continuous(name="Histogram Axis",
                         sec.axis = sec_axis(trans~./coef, name='Line Axis'))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多