论文
Evolution of immune genes is associated with the Black Death
https://www.nature.com/articles/s41586-022-05349-x
论文中Figure4的代码和数据是可以找到的,今天的推文来复现一下论文中的Figure4
image.png
论文中提供的数据和代码的链接 https://github.com/TaurVil/VilgalysKlunk_yersinia_pestis/
推文主要的学习点是patchwork包将ggplot2的多个图组合到一起
论文中具体的数据是什么意思暂时看的不是很明白,所以跳过论文中处理数据的代码,直接用处理好的数据来画图
加载需要用到的R包
代码语言:javascript复制library(tidyverse)
library(patchwork)
一个散点图
代码语言:javascript复制dat01<-read_delim("data/20231101/dat01.txt",
delim = "t")
dat01
p2 <- ggplot(dat01[dat01$TIME == "24h",], aes(x=PC1, y=PC2, color = factor(GT)))
geom_point(size=6)
theme_classic()
scale_color_manual(values = c("#00AFBB", "#E7B800", "#FC4E07"))
p2
一个箱线图
代码语言:javascript复制p1 <- ggplot(dat01, aes(x=factor(GT), y=PC1, fill=factor(GT)))
geom_boxplot() coord_flip()
theme_classic()
scale_color_manual(values = c("#00AFBB", "#E7B800", "#FC4E07"))
scale_fill_manual(values = c("#00AFBB", "#E7B800", "#FC4E07"))
xlab("genotype")
p1
image.png
四个箱线图
代码语言:javascript复制dat02<-read_delim("data/20231101/dat02.txt",
delim = "t")
dat02
p3<-dat02 %>%
filter(cytokine == "G-CSF") %>%
mutate(new_value=qqnorm(value, plot.it = F)$x) %>%
ggplot(aes(y=new_value, x=as.factor(status), fill=as.factor(gt)))
geom_boxplot(outlier.shape = NA)
ggtitle("G-CSF")
geom_jitter(width=0.2,col='gray45')
theme_classic()
scale_fill_manual(values = c("#00AFBB", "#E7B800", "#FC4E07"))
p3
p4<-dat02 %>%
filter(cytokine == "IL1B") %>%
mutate(new_value=qqnorm(value, plot.it = F)$x) %>%
ggplot(aes(y=new_value, x=as.factor(status), fill=as.factor(gt)))
geom_boxplot(outlier.shape = NA)
ggtitle("IL1B")
geom_jitter(width=0.2,col='gray45')
theme_classic()
scale_fill_manual(values = c("#00AFBB", "#E7B800", "#FC4E07"))
p4
p5<-dat02 %>%
filter(cytokine == "IL10") %>%
mutate(new_value=qqnorm(value, plot.it = F)$x) %>%
ggplot(aes(y=new_value, x=as.factor(status), fill=as.factor(gt)))
geom_boxplot(outlier.shape = NA)
ggtitle("IL10")
geom_jitter(width=0.2,col='gray45')
theme_classic()
scale_fill_manual(values = c("#00AFBB", "#E7B800", "#FC4E07"))
p5
p6<-dat02 %>%
filter(cytokine == "CCL3") %>%
mutate(new_value=qqnorm(value, plot.it = F)$x) %>%
ggplot(aes(y=new_value, x=as.factor(status), fill=as.factor(gt)))
geom_boxplot(outlier.shape = NA)
ggtitle("CCL3")
geom_jitter(width=0.2,col='gray45')
theme_classic()
scale_fill_manual(values = c("#00AFBB", "#E7B800", "#FC4E07"))
p6
image.png
所有图组合到一起
代码语言:javascript复制( p2 / p1 ) part2 plot_annotation(tag_levels = 'A')
plot_layout(guides = 'collect', nrow = 1, ncol=3,
widths = c(1,1,2))
image.png
小明的数据分析笔记本
小明的数据分析笔记本 公众号 主要分享:1、R语言和python做数据分析和数据可视化的简单小例子;2、园艺植物相关转录组学、基因组学、群体遗传学文献阅读笔记;3、生物信息学入门学习资料及自己的学习笔记!