复现SCI图表:ggplot2做双侧带误差线柱状图

近期有小伙伴发来一个文章(Identification and Validation of the lncRNA MYOSLID as a Regulating Factor of Necroptosis and Immune Cell Infiltration in Colorectal Cancer following Necroptosis-Related LncRNA Model Establishment)中的图表,想让复现一下,其实就是柱状图,之前我们做过很多,综合一下还是可以复现。这里我们大概复现一下!****示例数据及注释代码已上传群文件****。****

1、数据整理


df <- read.csv('df.csv', header = T)
df <- cbind(df[,1:7], df[,8:14]* -1) 

library(tidyr)
data <-gather(df, gene, value, 1:14)
data$group <- ''
data$group <- ifelse(data$value >0, "Up_regulation", "Down_regulation")

2、做柱状图

ggplot(data, aes(fill=group, y=value, x=reorder(gene,-value)))+
  geom_bar(position=position_dodge(),
           stat="summary",
           width=0.9,
           size=1)+ 
  stat_summary(fun.data = 'mean_se', 
               geom = "errorbar", 
               colour = "black",
               width = 0.2,
               position=position_dodge(0.7))+
  scale_fill_manual(values = c('#F69CA4','#EE2024'))+
  theme(axis.text.x = element_blank())+ 
  theme(axis.text.y = element_text(size = 12, color="black"),
        axis.line.y = element_line(color = 'black'),
        axis.title.y = element_text(size = 14, color="black"))+
  theme(axis.title.x = element_blank(),
        axis.ticks.x = element_blank())+
  theme(panel.grid = element_blank(),
        panel.background = element_blank())+
  theme(legend.position = 'none')+
  geom_hline(aes(yintercept=0),linetype=1,cex=1,color='black')+
  labs(title = "", y="Relative expression", x = "")+
  annotate(geom = 'text', label="Up_regulation", x=3.5, y=-15,size=4)+
  annotate("segment", x = 0.5, xend = 7.5, y = -10, yend = -10, color='black')+ 
  annotate(geom = 'text', label="Down_regulation", x=11.5, y=15,size=4)+
  annotate("segment", x = 8.5, xend = 13.5, y = 10, yend = 10, color='black')

3、添加散点

#当然了,如果你乐意,还可以加上散点,让样本量更加清晰,这也是很多杂志的要求
ggplot(data, aes(fill=group, y=value, x=reorder(gene,-value)))+
  geom_bar(position=position_dodge(),
           stat="summary",
           width=0.9,
           size=1)+ 
  stat_summary(fun.data = 'mean_se', 
               geom = "errorbar", 
               colour = "black",
               width = 0.2,
               position=position_dodge(0.7))+
  scale_fill_manual(values = c('#F69CA4','#EE2024'))+
  theme(axis.text.x = element_blank())+ 
  theme(axis.text.y = element_text(size = 12, color="black"),
        axis.line.y = element_line(color = 'black'),
        axis.title.y = element_text(size = 14, color="black"))+
  theme(axis.title.x = element_blank(),
        axis.ticks.x = element_blank())+
  theme(panel.grid = element_blank(),
        panel.background = element_blank())+
  theme(legend.position = 'none')+
  geom_hline(aes(yintercept=0),linetype=1,cex=1,color='black')+
  labs(title = "", y="Relative expression", x = "")+
  geom_jitter(data = data, aes(y = value,x=reorder(gene,-value)),
              size = 3, shape = 16,
              color="grey60",
              stroke = 0.15, show.legend = FALSE, 
              position = position_jitterdodge(jitter.height=0.5,
                                              jitter.width = 0.1,
                                              dodge.width = 0.8))

效果挺好的,至于文章中的中间有一个灰色的部分,添加分组就可以实现。觉得分享有用的点个赞、分享一下再走呗!

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值