近期有小伙伴发来一个文章(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))
图片
效果挺好的,至于文章中的中间有一个灰色的部分,添加分组就可以实现。觉得分享有用的点个赞、分享一下再走呗!
网友评论