跟着NaturePlants学作图:R语言ggplot2分组折线图完整示例
论文
The slow-evolving Acorus tatarinowii genome sheds light on ancestral monocot evolution
https://www.nature.com/articles/s41477-022-01187-x#Sec21
本地pdf s41477-022-01187-x.pdf
论文中的数据基本都公开了,我们可以利用论文中的数据模仿论文中的图,今天的推文模仿一下论文中Figure1c 和 figure1f
figure1c
部分示例数据截图
读取数据并作图
library(readxl)
datf3c<-read_excel("data/20220807/41477_2022_1187_MOESM4_ESM.xlsx",
sheet = "Fig.1C",
skip = 1)
head(datf3c)
library(tidyverse)
datf3c %>%
select(-'4dTV_1') %>%
pivot_longer(-'4dTV_2') %>%
mutate(name = fct_relevel(name,c("Acorus-Acorus",
"Acorus-Zostera",
"Acorus-Oryza",
"Acorus-Asparagus"))) -> new.datf3c
#install.packages("latex2exp")
library(latex2exp)
ggplot(data=new.datf3c,
aes(x=`4dTV_2`,y=value,color=name))+
geom_line(size=1)+
scale_color_manual(values = c("#ff0000","#7030a0",
"#00b050","#5b9bd5"),
name=NULL)+
theme_classic()+
theme(legend.position = c(0.8,0.8),
legend.text = element_text(face = "italic"))+
scale_x_continuous(expand = expansion(mult = c(0,0)),
limits = c(0,2),
breaks = seq(0,2,0.2))+
scale_y_continuous(expand = expansion(mult = c(0,0)),
limits = c(0,300))+
labs(x="4dTV",y="No.of gene pairs") -> p1
p1
figure1f
部分示例数据截图
读取数据并作图
datf3f<-read_excel("data/20220807/41477_2022_1187_MOESM4_ESM.xlsx",
sheet = "Fig.1F",
skip = 1)
head(datf3f)
datf3f %>%
pivot_longer(-"Distance to Gene Start") %>%
ggplot(aes(x=`Distance to Gene Start`,
y=value,
color=name))+
geom_line()+
scale_color_manual(values = c("#ff0000","#00b0f0"))+
theme_classic()+
theme(legend.position = c(0.9,0.2),
plot.margin = unit(c(0.1,0.5,0.1,0.1),'cm'),
legend.title = element_blank())+
scale_x_continuous(expand = expansion(mult = c(0,0)),
labels = c("-2 kb","Start","",
"Stop","+2 kb"))+
scale_y_continuous(expand = expansion(mult = c(0,0)),
limits = c(0,0.4))+
labs(x=NULL,y="Ratio of TEs") -> p2
p2
最后是拼图
p1+p2+
plot_annotation(tag_levels = list(c("c","f")))
欢迎大家关注我的公众号
小明的数据分析笔记本
小明的数据分析笔记本 公众号 主要分享:1、R语言和python做数据分析和数据可视化的简单小例子;2、园艺植物相关转录组学、基因组学、群体遗传学文献阅读笔记;3、生物信息学入门学习资料及自己的学习笔记!
共有 0 条评论