关于使用R中的ggplot2的两个因素的可信区间 [英] Credibility interval with respect two factors using ggplot2 in r

查看:125
本文介绍了关于使用R中的ggplot2的两个因素的可信区间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在绘制可信度间隔时遇到这样的问题:

I have problem ploting credibility interval like this:

我的数据结构如下,L1,L2,M,U1,U2分别代表0.025、0.25、0.5、0.75、0.975.

My data structure is following,L1,L2,M,U1,U2 stand for 0.025quant,0.25quant,0.5quant,0.75quant,0.975quant,respectively.

`

structure(list(approach = structure(c(1L, 2L, 1L, 2L, 1L, 2L), class = "factor", .Label = c("INLA", 
"rjags")), param = structure(c(1L, 2L, 3L, 1L, 2L, 3L), class = "factor", .Label = c("alpha", 
"beta", "sig2")), L1 = c(0.0844546867936143, 1.79242348175439, 
0.163143886545317, 0.0754165380733685, 1.79067991488052, 3.66675821267498
), L2 = c(0.60090835904286, 1.95337968870806, 0.898159977552433, 
0.606017177641373, 1.95260448314298, 4.07080184844179), M = c(0.870204161297956, 
2.03768437879748, 2.20651061559405, 0.87408237273113, 2.03725552264872, 
4.32531027636171), U2 = c(1.13905085248391, 2.12210930874551, 
4.26836270504725, 1.66260576926063, 2.28900567640091, 5.10063756831338
), U1 = c(1.65214011950274, 2.28396345192398, 4.9109804477583, 
1.1450384685802, 2.12117799328209, 4.55657971279654), AP = structure(c(1L, 
4L, 5L, 2L, 3L, 6L), .Label = c("INLA.alpha", "rjags.alpha", 
"INLA.beta", "rjags.beta", "INLA.sig2", "rjags.sig2"), class = "factor")), .Names = c("approach", 
"param", "L1", "L2", "M", "U2", "U1", "AP"), row.names = c(NA, 
-6L), class = "data.frame")`

我引用了此答案输入链接说明,但是"fill"似乎仅适用于箱线图情况.到目前为止,我尝试过的代码是:

I referenced this answerenter link description here,but 'fill' seems only work for boxplot case.the code I tried so far is:

CI$AP=interaction(CI$approach,CI$param)
p=ggplot(CI,aes(y=AP))+geom_point(aes(x=M))
p=p+geom_segment(aes(x=L1,xend=U1,y=AP,yend=AP))
p=p+geom_segment(aes(x=L2,xend=U2,y=AP,yend=AP),size=1.5)

它离我想要的很远.

非常感谢!

推荐答案

有关以下内容:

ggplot(df, aes(x = param, y = M, colour = approach)) +
    geom_point(position = position_dodge2(width = 0.3), size = 3) +
    geom_linerange(
        aes(ymin = L2, ymax = U2, x = param),
        position = position_dodge2(width = 0.3),
        size = 2) +
    geom_linerange(
        aes(ymin = L1, ymax = U1, x = param),
        position = position_dodge2(width = 0.3),
        size = 1) +
    coord_flip() +
    labs(x = "Parameter", y = "Estimate")

df <- structure(list(approach = structure(c(1L, 2L, 1L, 2L, 1L, 2L), class = "factor", .Label = c("INLA",
"rjags")), param = structure(c(1L, 2L, 3L, 1L, 2L, 3L), class = "factor", .Label = c("alpha",
"beta", "sig2")), L1 = c(0.0844546867936143, 1.79242348175439,
0.163143886545317, 0.0754165380733685, 1.79067991488052, 3.66675821267498
), L2 = c(0.60090835904286, 1.95337968870806, 0.898159977552433,
0.606017177641373, 1.95260448314298, 4.07080184844179), M = c(0.870204161297956,
2.03768437879748, 2.20651061559405, 0.87408237273113, 2.03725552264872,
4.32531027636171), U2 = c(1.13905085248391, 2.12210930874551,
4.26836270504725, 1.66260576926063, 2.28900567640091, 5.10063756831338
), U1 = c(1.65214011950274, 2.28396345192398, 4.9109804477583,
1.1450384685802, 2.12117799328209, 4.55657971279654), AP = structure(c(1L,
4L, 5L, 2L, 3L, 6L), .Label = c("INLA.alpha", "rjags.alpha",
"INLA.beta", "rjags.beta", "INLA.sig2", "rjags.sig2"), class = "factor")), .Names = c("approach",
"param", "L1", "L2", "M", "U2", "U1", "AP"), row.names = c(NA,
-6L), class = "data.frame")

这篇关于关于使用R中的ggplot2的两个因素的可信区间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆