The flying spider-monkey tree fern genome provides insights into fern evolution and arborescence
https://www.nature.com/articles/s41477-022-01146-6#Sec44
https://doi.org/10.6084/m9.figshare.19125641
今天的推文重复一下论文中的Figure1b左上角的小图
image.png
今天推文的主要知识点是如何在绘图区域外添加一些文本和线段的注释,这里需要用到annotation_custom()
函数
image.png
library(readxl)
dat01<-read_excel("data/20220524/Nature_plant_fig1b.xlsx")
head(dat01)
library(tidyverse)
dat01 %>%
mutate(new_col=rowMeans(.[,4:6])) -> new.dat
dftext<-data.frame(x=c(150,150,150,112.5),
y=c(15,70,95,20)/100,
label=c("0.03","66.83","88.97","Centromere"))
library(ggplot2)
ggplot()+
geom_line(data=new.dat,aes(x=Window,y=new_col,color=Context),
size=2)+
geom_vline(xintercept = 100,lty="dashed",
color="red",
size=1)+
geom_vline(xintercept = 125,lty="dashed",
color="red",
size=1)+
geom_text(data=dftext,aes(x=x,y=y,label=label))
image.png
并对主题进行一些修改
library(grid)
ggplot()+
geom_line(data=new.dat,aes(x=Window,y=new_col,color=Context),
size=2)+
geom_vline(xintercept = 100,lty="dashed",
color="red",
size=1)+
geom_vline(xintercept = 125,lty="dashed",
color="red",
size=1)+
geom_text(data=dftext,aes(x=x,y=y,label=label))+
coord_cartesian(clip = "off")+
annotation_custom(grob = linesGrob(gp=gpar(col="#e9d3ff",
lwd=8,
lineend="square")),
xmin=0,xmax=100,
ymin=-0.08,
ymax=-0.08)+
annotation_custom(grob = linesGrob(gp=gpar(col="#e9d3ff",
lwd=8,
lineend="square")),
xmin=125,xmax=225,
ymin=-0.08,
ymax=-0.08)+
annotation_custom(grob = linesGrob(gp=gpar(col="#f7931e",
lwd=8,
lineend="square")),
xmin=0,xmax=1,
ymin=-0.08,
ymax=-0.08)+
annotation_custom(grob = linesGrob(gp=gpar(col="#93278f",
lwd=8,
lineend="square")),
xmin=99,xmax=100,
ymin=-0.08,
ymax=-0.08)+
annotation_custom(grob = linesGrob(gp=gpar(col="#93278f",
lwd=8,
lineend="square")),
xmin=124,xmax=125,
ymin=-0.08,
ymax=-0.08)+
annotation_custom(grob = linesGrob(gp=gpar(col="#f7931e",
lwd=8,
lineend="square")),
xmin=224,xmax=225,
ymin=-0.08,
ymax=-0.08)+
annotation_custom(grob = pointsGrob(pch=19,
size=unit(0.8,'char')),
xmin=112.5,ymin=-0.08,
xmax=112.5,ymax=-0.08)+
annotation_custom(grob = segmentsGrob(gp=gpar(col="black",
lwd=2,
lineend="square"),
arrow = arrow()),
xmin=112.5,
ymin=0.125,
xmax=112.5,
ymax=-0.02)+
annotation_custom(grob = segmentsGrob(gp=gpar(col="black",
lwd=2,
lineend="square"),
arrow = arrow(angle=20,
length = unit(2,'mm'))),
xmin=100,
ymin=-0.2,
xmax=100,
ymax=-0.08)+
annotation_custom(grob = segmentsGrob(gp=gpar(col="black",
lwd=2,
lineend="square"),
arrow = arrow(angle=20,
length = unit(2,'mm'))),
xmin=125,
ymin=-0.2,
xmax=125,
ymax=-0.08)+
annotation_custom(grob = textGrob(label = "Pericentromeric regions",
just = "top",
hjust=0.5),
xmin=112.5,
ymin=-0.2,
xmax=112.5,
ymax=-0.2)+
annotation_custom(grob = segmentsGrob(gp=gpar(col="black",
lwd=2,
lineend="square"),
arrow = arrow(angle=20,
length = unit(2,'mm'))),
xmin=225,
ymin=-0.2,
xmax=225,
ymax=-0.08)+
annotation_custom(grob = textGrob(label = "Teloere",
just = "top",
hjust=0.5),
xmin=225,
ymin=-0.2,
xmax=225,
ymax=-0.2)+
scale_y_continuous(limits = c(0,1),
breaks = seq(0,1,0.25),
labels = seq(0,1,0.25)*100)+
scale_color_manual(values = c("#66c2a5","#fc8d62","#8da0cb"))+
labs(x="",y="Methylation level (%)")+
theme_bw()+
theme(axis.text.x = element_blank(),
axis.ticks.x = element_blank(),
plot.margin = unit(c(0.1,0.1,2,0.1),'cm'),
panel.grid = element_blank())
最终结果如下
image.png
说实话,额外注释的位置真不好搞,这些额外注释可能还是出图后借助其他软件来编辑比较合适
示例数据可以到论文中去下载,代码可以在推文中复制