論文
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
今天的推文重復(fù)一下論文中的Figure3签舞,涉及到4個(gè)圖巴席,普通箱線圖这敬,分組箱線圖讼庇,箱線圖分面拐辽,最后一個(gè)知識(shí)點(diǎn)是如何將這5個(gè)圖組合到一起
首先是定義了ggplot2的主題
library(ggplot2)
My_Theme <- theme(
panel.background = element_blank(),
title = element_text(size = 7),
text = element_text(size = 6))
第一個(gè)普通的箱線圖
部分示例數(shù)據(jù)集
讀取數(shù)據(jù)集
library(readxl)
dat01<-read_excel("data/20220627/Fig3.xlsx",
sheet = "3a")
作圖代碼
p1 <- ggplot(data = dat01, aes(x = group)) +
geom_boxplot(alpha=0.6,
notch = TRUE,
notchwidth = 0.5,
aes(y=hsq, fill=kind)) +
coord_cartesian(ylim = c(0,0.5)) +
labs(y = expression(paste("cis-",h^2)),
x=NULL, title=NULL) +
theme(legend.position="top",
legend.title=element_blank(),
axis.text.x = element_text(color = c("#4a1486",
"#4a1486",
"#cb181d",
"#cb181d"),
vjust = 0.5,
hjust = 0.5,
angle = 15))+
My_Theme+
scale_fill_manual(values=c("#4a1486","#cb181d"))+
theme(axis.line = element_line())
p1
分組箱線圖
作圖代碼
dat02<-read_excel("data/20220627/Fig3.xlsx",
sheet = "3b")
head(dat02)
p2 <- ggplot(data = dat02, aes(x = group)) +
geom_boxplot(alpha=0.8,
notch = TRUE,
notchwidth = 0.5,
aes(y=acc, fill=Model)) +
coord_cartesian(ylim = c(0,1.2)) +
labs(title = NULL, x=NULL,
y=expression(paste(R^2,"/cis-",h^2))) +
theme(legend.position="top",
axis.text.x = element_text(color = c("#4a1486",
"#4a1486",
"#cb181d",
"#cb181d"),
vjust = 0.5,
hjust = 0.5,
angle = 15))+
My_Theme+
scale_fill_manual(values=c("#feb24c","#41b6c4"))+
theme(axis.line = element_line())
p2
箱線圖分面
dat03<-read_excel("data/20220627/Fig3.xlsx",
sheet = "3c")
head(dat03)
p3 <- ggplot(data = dat03, aes(x = model)) +
geom_boxplot(alpha=0.8,
notch = TRUE,
notchwidth = 0.5,
aes(y=acc, fill=model)) +
facet_wrap(~race, ncol=2)+
labs(title = NULL, x=NULL,
y=expression(paste(R^2,"/cis-",h^2))) +
coord_cartesian(ylim = c(0,1.2)) +
theme(axis.text.x = element_text(color = c("#238b45",
"#2171b5"),
vjust = 0.5,
hjust = 0.5,
angle = 15),
legend.position="none") +
My_Theme+
scale_fill_manual(values=c("#238b45","#2171b5"))+
theme(axis.line = element_line(),
panel.spacing.x = unit(0,'lines'),
strip.background = element_rect(color="white"))
p3
這里兩個(gè)小知識(shí)點(diǎn)揽浙,
默認(rèn)分面兩個(gè)圖之間是有空白的冬念,如果想沒有這個(gè)空白可以在主題里進(jìn)行設(shè)置
panel.spacing.x = unit(0,'lines')
兩個(gè)圖中間沒有空白提前,上面灰色區(qū)域的地方如果想?yún)^(qū)分開支竹,可以將邊框顏色設(shè)置為白色
strip.background = element_rect(color="white")
最后一個(gè)箱線圖
dat04<-read_excel("data/20220627/Fig3.xlsx",
sheet = "3d")
head(dat04)
gtex.colors <- read_excel("data/20220627/gtex_colors.xlsx")
gtex.colors
myColors <- gtex.colors$V2
names(myColors) <- gtex.colors$V1
colScale <- scale_fill_manual(name = "gtex.colors", values = myColors)
p4 <- ggplot(data = dat04, aes(x = tissue, fill=tissue)) +
geom_boxplot(alpha=0.8,
notch = TRUE,
notchwidth = 0.5,
aes(y=cor)) +
theme(axis.text.x = element_text(angle = 90, hjust = 1),
legend.position="none",
axis.title.y = element_text(hjust=1))+
My_Theme+
coord_cartesian(ylim = c(-0.25,1))+
colScale +
labs(x = "GTEx V7 tissue",
y = "Correlation between cis-regulated gene \nexpression and plasma protein SOMAmers ",
title=NULL)+
theme(axis.line = element_line())
p4
將四個(gè)圖組合到一起
library(ggpubr)
p <- ggarrange(ggarrange(p1, p2,
p3,
ncol = 3, labels = c("a", "b","c"),
widths = c(0.29,0.4,0.31)),
p4,
nrow = 2, heights = c(0.5,0.5),
labels = c(NA,"d"))
p
示例數(shù)據(jù)和代碼可以自己到論文中獲取旋廷,或者給本篇推文點(diǎn)贊,點(diǎn)擊在看礼搁,然后留言獲取
歡迎大家關(guān)注我的公眾號(hào)
小明的數(shù)據(jù)分析筆記本
小明的數(shù)據(jù)分析筆記本 公眾號(hào) 主要分享:1饶碘、R語(yǔ)言和python做數(shù)據(jù)分析和數(shù)據(jù)可視化的簡(jiǎn)單小例子;2馒吴、園藝植物相關(guān)轉(zhuǎn)錄組學(xué)扎运、基因組學(xué)、群體遺傳學(xué)文獻(xiàn)閱讀筆記饮戳;3豪治、生物信息學(xué)入門學(xué)習(xí)資料及自己的學(xué)習(xí)筆記!