ggplot绘制对比图

library(ggplot2)
library(ggsci)
plot <-c ("A","A","B","B","C","C","D","D")
mean <- c(2.5,-3.2,3.1,-3.6,4,-5,4.8,-4.3)
se <- c(0.5,-0.4,0.3,-0.2,0.6,-0.5,0.3,-0.5)
type <- c("A1","A2","A1","A2","A1","A2","A1","A2")
Label <- c("端","学","午","业","安","有","康","成")
df <- data.frame(plot,mean,se ,type,Label)
library(ggpubr)
tiff(file="1..tiff",res=600,width=4000,height=3000,compression="lzw")
ggplot(data=df,aes(x=plot,y=mean,fill=type))+
geom_bar(stat="identity",position =  'stack',width = 0.6)+ 
geom_errorbar(aes(ymin=mean-se,ymax=mean+se),position = position_dodge(0), width = 0.2)+
geom_text(data = df,aes(x =plot, y=mean+ mean*0.6, label = Label,color = type),angle = 0,size =4)+  
scale_y_continuous(limits = c(-15,15),breaks = c(-15,-10,-5,0,5,10,15),labels = c(15,10,5,0,5,10,15))+scale_fill_lancet()+scale_color_lancet()+
geom_hline(aes(yintercept = 0),size = 0.2)+theme_bw()+
theme(legend.direction = 'horizontal',axis.text = element_text(size = 12,hjust = 0.5,face = 'bold',color = 'black'), axis.title = element_text(size = 14,hjust = 0.5,face = 'bold',color = 'black'),
legend.text = element_text(size = 12,hjust = 0.5,face = 'bold',color = 'black'),
legend.title = element_text(size = 14,hjust = 0.5,face = 'bold',color = 'black'),
panel.grid = element_line(color = 'transparent'))+ ylab('Mean')+xlab(NULL)+theme(legend.position = c(0.5,0.1))+theme(legend.title = element_blank())
dev.off()

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值