跟着Nature Genetics学作图:R语言ggplot2散点图突出强调其中某些点

论文

Plasma proteome analyses in individuals of European and African ancestry identify cis-pQTLs and models for proteome-wide association studies

https://www.nature.com/articles/s41588-022-01051-w

本地pdf s41588-022-01051-w.pdf

代码链接

https://zenodo.org/record/6332981#.YroV0nZBzic

https://github.com/Jingning-Zhang/PlasmaProtein/tree/v1.2

今天的推文重复一下论文中的Extended Data Fig. 1

image.png

这里是散点图,然后突出显示其中某些点。论文里的处理方式是把指定的数据筛选出来,做好散点图后再叠加过滤后的数据。

这里还新接触到一个R包 mdthemes 可以解析代码中的markdown语法

https://github.com/thomas-neitmann/mdthemes

部分示例数据集截图

image.png

第一个图的代码

df<-read.delim("ExtendedDataFig1.txt",
               sep="/t",
               header = TRUE)

df.EA <- df[df$eth=="EA",]
df.EA_highlight <- df.EA[c(865,1391,1342,277), ]
df.EA_highlight
df.text<-df.EA_highlight
df.text$label<-letters[1:4]

df.text$label<-c("EA:0.021/nAA:0.035",
                 "EA:0.237/nAA:0.092",
                 "EA:0.056/nAA:0.139",
                 "EA:0.234/nAA:0.013")

library(ggplot2)
library(latex2exp)
#install.packages("mdthemes")
help(package="mdthemes")
library(mdthemes)
library(ggrepel)

My_Theme = theme(
  panel.background = element_blank(), 
  title = element_text(size = 7),
  text = element_text(size = 6)
  # axis.title.x = element_text(size = 10),
  # axis.text.x = element_text(size = 8),
  # axis.title.y = element_text(size = 10),
  # axis.text.y = element_text(size = 8),
  # legend.title = element_text(size = 10)
  # legend.text = element_text(size = 8)
)

p.EA <- ggplot(data = df.EA, aes(x = Beta_EA, y = Beta_AA)) + 
  geom_point(size=0.5, col="#2171b5") +
  geom_abline(intercept = 0, slope = 1, col="red") +
  theme(axis.line = element_line(color="black", size = 0.2)) +
  ylim(-2,2)+xlim(-2,2)+
  mdthemes::md_theme_classic() +
  labs(x = "Effect size (EA)", 
       y = "Effect size (AA)",
       title="Common sentinel SNP of *cis*-pQTLs in EA") +
  My_Theme +
  geom_point(data=df.EA_highlight, 
             aes(x = Beta_EA, y = Beta_AA),
             size=5, col="darkorange")+
  geom_text_repel(data=df.text,
            aes(x = Beta_EA, y = Beta_AA,label=label),
            color="darkorange",seed=5678)

p.EA
image.png

第二个图的代码

df.AA <- df[df$eth=="AA",]
df.AA_highlight <- df.AA[c(893,59,710,168), ]

df.text.AA<-df.AA_highlight
df.text.AA$label<-letters[1:4]
df.text.AA$label<-c("EA:0.075/nAA:0.104",
                    "EA:0.056/nAA:0.139",
                    "EA:0.015/nAA:0.093",
                    "EA:0.014/nAA:0.368")

p.AA <- ggplot(data = df.AA, aes(x = Beta_AA, y = Beta_EA)) + 
  geom_point(size=0.5,col="#238b45") +
  geom_abline(intercept = 0, slope = 1, col="red") +
  theme(axis.line = element_line(color="black", size = 0.2)) +
  ylim(-2,2)+xlim(-2,2)+
  mdthemes::md_theme_classic() +
  labs(x = "Effect size (AA)", 
       y = "Effect size (EA)",
       title="Common sentinel SNP of *cis*-pQTLs in AA"
  ) +
  My_Theme +
  geom_point(data=df.AA_highlight, aes(x = Beta_AA, y = Beta_EA),
             size=5, col="darkorange")+
  geom_text_repel(data=df.text.AA,
                  aes(x = Beta_AA, y = Beta_EA,
                      label=label),
                  seed=5678,
                  color="darkorange")
p.AA
image.png

拼图代码

library(cowplot)
p <- cowplot::plot_grid(p.EA, p.AA, ncol=2)
p
image.png

示例数据和代码可以自己到论文中获取,或者给本篇推文点赞,点击在看,然后留言获取

欢迎大家关注我的公众号

小明的数据分析笔记本

小明的数据分析笔记本 公众号 主要分享:1、R语言和python做数据分析和数据可视化的简单小例子;2、园艺植物相关转录组学、基因组学、群体遗传学文献阅读笔记;3、生物信息学入门学习资料及自己的学习笔记!

版权声明:
作者:Alex
链接:https://www.techfm.club/p/63872.html
来源:TechFM
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
< <上一篇
下一篇>>