[英]plotting average with confidence interval in ggplot2 for time-series data
[英]subset data with confidence interval in ggplot2
我有一个像这样的数据框:
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只绘X的值geom_point
,其中x = ID和y =比率。
其次,我想使用值的完整列表作为置信区间,作为X的绘制值。最后,绘制应如下所示:
这是使用伪造数据的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()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.