如何使用ggplot2(R)绘制单个置信区间?
我试图用如何使用ggplot2(R)绘制单个置信区间?,r,ggplot2,R,Ggplot2,我试图用ggplot在单个图形上显示单个置信区间 当前代码 d1<-rnorm(50,26,6) d2<-rnorm(20,19,4) all_test<-t.test(d1,d2) mean_CI<-(all_test$conf.int[2]+all_test$conf.int[1])/2 ggplot(data.frame(x=c()), aes(x)) + geom_segment(aes(x = 0, y = all_test$conf.int[
ggplot
在单个图形上显示单个置信区间
当前代码
d1<-rnorm(50,26,6)
d2<-rnorm(20,19,4)
all_test<-t.test(d1,d2)
mean_CI<-(all_test$conf.int[2]+all_test$conf.int[1])/2
ggplot(data.frame(x=c()), aes(x)) +
geom_segment(aes(x = 0, y = all_test$conf.int[1], xend = 0, yend = all_test$conf.int[2]), arrow = arrow(length = unit(0.02, "npc"),type = "closed",ends="both")) +
annotate("point", x = 0, y = mean_CI,size =4)+
geom_hline(yintercept = 0, linetype = 3, size =1.5) +
theme_classic()
d1使用geom_errorbar
和geom_point
可以这样实现:
库(ggplot2)
种子(42)
d1