一个带有误差棒的另一个箱图
作者:互联网
今天遇到一个图,需要有R绘制一个展示平均数,误差的的点图,并进行数据统计,如下图所示
数据格式如下
data
library(ggplot2)
p=ggplot(data,aes(x = group,y = mean,color = group))+
xlab('')+ylab('Percent %')+
facet_wrap(~metacluster,scales = 'free')+
geom_errorbar(aes(ymin=mean-sd, ymax=mean+sd),
width=.2,position=position_dodge(.9))+
geom_point(aes(x = group,y = mean,shape=group))+
theme(panel.grid.major =element_blank(),
panel.grid.minor = element_blank(),
panel.background = element_rect(fill = 'transparent',colour ='gray'),
panel.border=element_rect(fill=NA,colour='black'),
plot.background = element_rect(fill = 'transparent',colour ='gray'),
legend.position = 'top')
#加显著性
data_p
data_p1=data_p[which(data_p$lab=='*'),]
#geom_text添加显著性的*
#加横线
geom_segment
p1=p+geom_text(aes(label = lab),
nudge_x=-0.5,
nudge_y=24,color ="black")+
geom_segment(aes(x = 1 ,xend = 2,
y = 24,yend = 24),
data=data_p1,
color ='black')
标签:误差,aes,group,箱图,geom,带有,element,data,panel 来源: https://blog.csdn.net/weixin_43949246/article/details/113663592