跟着Oncogene学作图:R语言gggenomes画桑基图(共线性图)
2023-02-19 12:27:51 时间
论文
Single-cell RNA sequencing reveals distinct tumor microenvironmental patterns in lung adenocarcinoma
https://www.nature.com/articles/s41388-021-02054-3
这个是公众号读者的留言,问下图如何实现
image.png
论文中没有提供数据和代码,我们简单构造一个示例数据,然后代码自己写
这个图可以用桑基图的画法来做,之前的推文介绍了两个桑基图的做法
今天的推文介绍一下gggenomes这个R包,这个是用来做基因组共线性的图的,但是共线性和桑基图看起来效果是一样的,所以桑基图也可以用这个来做
github主页
https://github.com/thackl/gggenomes
安装代码
devtools::install_github("thackl/gggenomes")
安装过程会更新很多R包,会遇到一些报错,自己搜索报错提示信息应该能够解决
首先是一个简单的小例子
示例数据
image.png
读取数据作图
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))
image.png
添加两个图之间的阴影
image.png
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")
image.png
接下来是模仿论文中的那个图
示例数据
image.png
读取数据并作图
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)
image.png
最后是制作封面图
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
相关文章
- git下载子模块失败问题解决办法
- 基于Jekyll与Github Pages搭建博客
- HTML5项目笔记3:使用Canvas设计离线系统的Logo
- linux系统开mc服务器
- 红队技术-Cobaltstrike之Linux上线
- 权限维持-Linux后门
- 万万没想到,go的数据库操作,也能像php一样溜了
- Typora+PicGo+GitHub实现图片快速上传
- Linux计划任务服务程序
- 2022 如何在 GitHub 上搭建个人网站(github.io)
- 虚拟机安装linux无法访问外网解决办法
- 用过 mongodb 吧, 这三个大坑踩过吗?
- 教你配置windows上的windbg,linux上的lldb,打入clr内部这一篇就够了
- MongoDB 在评论中台的实践
- 使用mongodb作为Quartz.Net下的JobStore实现底层的持久化机制
- mongodb之使用explain和hint性能分析和优化
- mongodb 3.x 之实用新功能窥看[2] ——使用$lookup做多表关联处理
- mongodb 3.x 之实用新功能窥看[1] ——使用TTLIndex做Cache处理
- 双十一来了,别让你的mongodb宕机了
- GO语言开发环境搭建笔记