跟着Nature Communications学作图:R语言ggplot2散点图/折线图/误差线展示基因表达量

2023-11-21 17:16:49 浏览数 (2)

论文

Genomic insights into local adaptation and future climate-induced vulnerability of a keystone forest tree in East Asia

https://www.nature.com/articles/s41467-022-34206-8

论文的代码链接

https://github.com/jingwanglab/Populus_genomic_prediction_climate_vulnerability

今天的推文我们尝试复现一下论文中的figure3e和figure3i

image.png

image.png

figure3e的示例数据

image.png

读取数据并作图

代码语言:javascript复制
p1<-ggplot(data = dat.fig3e,aes(x=hour,y=relative_expression)) 
  geom_point(aes(color=base),size=5) 
  geom_line(aes(color=base),
            show.legend = FALSE) 
  geom_errorbar(aes(ymin=relative_expression-STD,
                    ymax=relative_expression STD,color=base),
                width=0.4) 
  theme_bw(base_size = 20) 
  theme(panel.grid = element_blank(),
        legend.position = c(0.2,0.8)) 
  scale_color_manual(values = c("ALT"="#a2c0e4",
                                "REF"="#2d52a2"),
                     labels=c("CC","TC"),
                     name=NULL) 
  labs(x="Time since submergence stress",
       y="Expression")

p1

image.png

figure3i 数据截图

image.png

作图代码基本和fig3e的一致

但是这里的时间跨度从0,1,2,3突然跨到24,这样出图不是很好看,我们把24改成4,然后在坐标轴标签上再改为24

代码语言:javascript复制
p2<-ggplot(data = dat.fig3i,aes(x=hour,y=relative_expression)) 
  geom_point(aes(color=base),size=5) 
  geom_line(aes(color=base),
            show.legend = FALSE) 
  geom_errorbar(aes(ymin=relative_expression-STD,
                    ymax=relative_expression STD,color=base),
                width=0.2) 
  theme_bw(base_size = 20) 
  theme(panel.grid = element_blank(),
        legend.position = c(0.2,0.8)) 
  scale_color_manual(values = c("ALT"="#e1c4c4",
                                "REF"="#b0383f"),
                     labels=c("AA","GG"),
                     name=NULL) 
  labs(x="Time since heat stress",
       y="Expression") 
  scale_x_continuous(breaks = 0:4,
                     labels = paste0(c(0,1,2,3,24),"h"))
p2

image.png

最后是将两个图组合到一起

代码语言:javascript复制
library(patchwork)

p1 p2

image.png

0 人点赞