论文
Single-cell RNA sequencing reveals distinct tumor microenvironmental patterns in lung adenocarcinoma
https://www.nature.com/articles/s41388-021-02054-3
这个是公众号读者的留言,问下图如何实现
论文中没有提供数据和代码,我们简单构造一个示例数据,然后代码自己写
这个图可以用桑基图的画法来做,之前的推文介绍了两个桑基图的做法
今天的推文介绍一下gggenomes这个R包,这个是用来做基因组共线性的图的,但是共线性和桑基图看起来效果是一样的,所以桑基图也可以用这个来做
github主页
https://github.com/thackl/gggenomes
安装代码
devtools::install_github("thackl/gggenomes")
安装过程会更新很多R包,会遇到一些报错,自己搜索报错提示信息应该能够解决
首先是一个简单的小例子
示例数据
读取数据作图
library(readxl)
library(gggenomes)
df<-read_excel("gggenomes_examples.xlsx",
sheet="Sheet1")
df
gggenomes(genes = df)+
geom_gene()
gggenomes(genes = df)+
geom_gene(shape=0,aes(fill=group))
添加两个图之间的阴影
dflink<-read_excel("gggenomes_examples.xlsx",sheet = "Sheet2")
dflink
gggenomes(genes = df,links = dflink)+
geom_link(offset = 0.05,aes(fill=group2))+
geom_gene(shape=0,aes(fill=group),size=5)+
theme(legend.position = "none")
接下来是模仿论文中的那个图
示例数据
读取数据并作图
dflink<-read_excel("gggenomes_examples.xlsx",sheet = "Sheet2")
dflink
gggenomes(genes = df,links = dflink)+
geom_link(offset = 0.05,aes(fill=group2))+
geom_gene(shape=0,aes(fill=group),size=5)+
theme(legend.position = "none")
df3<-read_excel("gggenomes_examples.xlsx",
sheet = "Sheet3")
df3
df3 %>%
filter(seq_id=="Normal") %>%
mutate(length=end-start+1) -> dflink01
df3 %>%
filter(seq_id=="Tumor") %>%
mutate(length=end-start+1) -> dflink02
bind_cols(dflink01,dflink02) -> dflinks
colnames(dflinks)<-c(c("seq_id","start","end","group",'length'),
paste0(c("seq_id","start","end","group",'length'),2))
dflinks
gggenomes(genes=df3,links = dflinks)+
geom_bin_label(size=5)+
geom_link(aes(fill=group),offset = 0.3)+
geom_gene(aes(fill=group),shape=0,
size=10)+
theme(legend.position = "none",
axis.line.x = element_blank(),
axis.ticks.x=element_blank(),
axis.text.x = element_blank())+
xlim(-15,100)+
scale_fill_manual(values =as.vector(tidyquant::palette_dark()))+
annotate(geom = "segment",
x=0,xend = 100,y = 0.5,yend=0.5)+
geom_segment(data=data.frame(x=c(0,50,100),
xend=c(0,50,100),
y=c(0.5,0.5,0.5),
yend=c(0.4,0.4,0.4)),
aes(x=x,xend=xend,y=y,yend=yend),
inherit.aes = FALSE)+
geom_text(data=data.frame(x=c(0,50,100),
y=c(0.4,0.4,0.4),
label=c("0.0",'0.5','1.0')),
aes(x=x,y=y,label=label),vjust=1)
最后是制作封面图
gggenomes(genes=df3,links = dflinks)+
geom_bin_label(size=5)+
geom_link(aes(fill=group),offset = 0.3)+
geom_gene(aes(fill=group),shape=0,
size=10)+
theme(legend.position = "none",
axis.line.x = element_blank(),
axis.ticks.x=element_blank(),
axis.text.x = element_blank())+
xlim(-15,100)+
scale_fill_manual(values =as.vector(tidyquant::palette_dark()))+
annotate(geom = "segment",
x=0,xend = 100,y = 0.5,yend=0.5)+
geom_segment(data=data.frame(x=c(0,50,100),
xend=c(0,50,100),
y=c(0.5,0.5,0.5),
yend=c(0.4,0.4,0.4)),
aes(x=x,xend=xend,y=y,yend=yend),
inherit.aes = FALSE)+
geom_text(data=data.frame(x=c(0,50,100),
y=c(0.4,0.4,0.4),
label=c("0.0",'0.5','1.0')),
aes(x=x,y=y,label=label),vjust=1) -> p1
gggenomes(genes=df3,links = dflinks)+
geom_bin_label(size=5)+
geom_link(aes(fill=group),offset = 0.3)+
geom_gene(aes(fill=group),shape=0,
size=10)+
theme(legend.position = "none",
axis.line.x = element_blank(),
axis.ticks.x=element_blank(),
axis.text.x = element_blank())+
xlim(-15,100)+
scale_fill_manual(values =as.vector(tidyquant::palette_light())) -> p2
library(patchwork)
p2/p1
公众号 小明的数据分析笔记本 有获取示例数据和代码的方式
欢迎大家关注我的公众号
小明的数据分析笔记本
小明的数据分析笔记本 公众号 主要分享:1、R语言和python做数据分析和数据可视化的简单小例子;2、园艺植物相关转录组学、基因组学、群体遗传学文献阅读笔记;3、生物信息学入门学习资料及自己的学习笔记!