【问题标题】:subset data with confidence interval in ggplot2ggplot2中具有置信区间的子集数据
【发布时间】:2016-11-27 21:07:48
【问题描述】:

我有一个这样的数据框:

ID Value Ratio
P1 W 0.512
P1 X 0.444
P1 Y 0.342
P1 Z 0.617
...
P2 W 0.400
P2 X 0.333
P2 Y 0.200
P2 Z 0.500
...
P3 W 0.250
P3 X 0.500
P3 Y 0.667
P3 Z 0.750
...

首先,我希望 ggplot 仅绘制 geom_point 中 X 的值,x=ID 和 y=Ratio。

其次,对于 X 的绘制值,我想使用完整的值列表作为置信区间。最后,绘图应如下所示:

【问题讨论】:

  • 你能给我们一个可重现的例子并展示你试图做什么吗?

标签: r ggplot2 subset confidence-interval


【解决方案1】:

这是一个使用假数据的 50% 和 95% 置信区间示例:

library(ggplot2)

# Fake data
set.seed(295)
dat = data.frame(ID=rep(paste0("P",1:3),each=20), ratio=runif(60,0,1))

ggplot(dat, aes(ID, ratio)) +
  stat_summary(fun.data=mean_cl_boot, geom="errorbar", size=0.7, 
               width=0.03, colour="red") +
  stat_summary(fun.data=mean_cl_boot, fun.args=list(conf.int=0.5), 
               geom="errorbar", size=5, width=0, color="lightblue") +
  stat_summary(fun.y=mean, geom="point", colour="red", pch="_", size=6) +
  scale_y_continuous(limits=c(0,1)) +
  theme_bw()

【讨论】:

    猜你喜欢
    • 2018-11-08
    • 2021-12-22
    • 2018-01-24
    • 1970-01-01
    • 2012-12-13
    • 1970-01-01
    • 2014-02-08
    • 2016-05-11
    • 2019-06-24
    相关资源
    最近更新 更多