用R语言的ggplot2包复现一下Nature正刊论文中的气泡图

论文

Temporal dynamics of the multi-omic response to endurance exercise training
https://www.nature.com/articles/s41586-023-06877-w
之前的推文介绍过这篇论文里的转录组数据处理流程,
学习Nature正刊论文里的转录组数据处理流程
有公众号读者留言问到这篇论文里的Figure4应该如何做。今天的推文先介绍一下Figure4a (这个图讲的是什么内容暂时还看不明白)
Figure4a 的主体是一个气泡图,然后用曲线线段连接点,曲线线段可以用 geom_curve()函数来实现
比如
library(ggplot2)

ggplot()+
annotate(geom = “curve”,
x=1,xend=5,y=1,yend=1,
curvature=0)

ggplot()+
annotate(geom = “curve”,
x=1,xend=5,y=1,yend=1,
curvature=-0.5)
curvature=0 这个参数设置为0 就是直线,改成其他数值就是带有弧度的线,正负值可以改变弧度的方向,但是遇到一个问题是 入果用geom_curve()这个函数的话 curvature 是不能放到aes()里的,在网上搜了搜,也有人讨论到这个问题
https://stackoverflow.com/questions/55627528/how-can-i-pass-individual-curvature-arguments-in-ggplot2-geom-curve-functi (我把我找到的方案也放到这个链接里了,这个是自己第一次在这个网站上回答问题)

image.png
linkET 这个R包里有一个函数 geom_curve2() 可以将 curvature 放到aes()里的,但是遇到一个问题,正常一个R包里的函数运行命令,比如ggplot2的散点图函数,运行如下命令
ggplot2::geom_point()
会正常有一些输出
这个 geom_curve2() 函数 运行 linkET::geom_curve2() 会报错
Error: ‘geom_curve2’ is not an exported object from ‘namespace:linkET’
暂时不知道啥原因
把这个R包里 geom_curve2.R 和 utils.R文件的内容全部复制到一个文件里,通过source()的方式载入
source(“usefulFunction/geom_curve2.R”)
可以正常运行这个函数
准备的示例数据

image.png

image.png
读取数据

library(tidyverse)
library(readxl)

dat01<-read_excel(“2024.data/20240611/dat01.xlsx”)
dat02<-read_excel(“2024.data/20240611/dat02.xlsx”)

dat02
dat01 %>%
pivot_longer(cols = c(“sample1″,”sample2″,”sample3″,”sample4”),
names_to = “X”,values_to = “value”) %>%
mutate(newY=as.integer(Y %>% as.factor()),
newX=as.integer(X %>% as.factor())) -> dat01.longer
作图代码

source(“usefulFunction/geom_curve2.R”)
ggplot()+
geom_curve2(data=dat02,
aes(x=startx,xend=endx,
y=starty,yend=endy,
size=size,
curvature=curvature,
color=group),
node.color=NA,
node.fill=NA)+
annotate(geom=”label”,x=0,y=4,label=”No change”,
label.size=NA,fill=”grey”,size=10)+
scale_color_manual(values = c(“A”=”#ff8000”,
“B”=”#019e74”,
“D”=”#397eb9”))+
ggnewscale::new_scale_color()+
ggnewscale::new_scale(“size”)+
geom_point(data=dat01.longer,
aes(x=newX,y=newY,size=value,color=group))+
scale_size_continuous(range=c(5,15))+
scale_color_manual(values = c(“groupA”=”#ce0001”,
“groupC”=”#bebebe”,
“groupB”=”#0000ff”))+
theme_void()+
xlim(-0.5,NA)

image.png
欢迎大家关注我的公众号

声明:文中观点不代表本站立场。本文传送门:https://eyangzhen.com/417616.html

(0)
联系我们
联系我们
分享本页
返回顶部