CELL_all.jpg
今天要復(fù)現(xiàn)的圖來自2019年的一篇Nature传趾。也是非常經(jīng)典的一篇組學(xué)文章。文章其它的圖都比較常見泥技,Fig1
還是比較有意思的浆兰,咱們今天就來復(fù)現(xiàn)一下。
Snipaste_2021-10-25_22-19-22
讀圖
Snipaste_2021-10-23_21-27-34
Snipaste_2021-10-25_22-31-24
樣本首先按AFP(甲胎蛋白)水平排列(從低AFP(≤200,灰色)到高AFP(>200,紅色)珊豹,然后按MVI(從MVI否到MVI是)排序簸呈。成對(duì)的樣本用灰色直線標(biāo)注。擬合的虛線曲線顯示了蛋白質(zhì)在腫瘤(紅色店茶,n=98)和非腫瘤(藍(lán)色蜕便,n=98)樣本中的分布。陰影表示95%的置信區(qū)間忽妒。
思路
- 兩步走玩裙,分別做分類變量的格子熱圖和啞鈴圖兼贸。
- 先將AFP從低到高排列,再分為低和高吃溅。注意改變因子
level
溶诞。 - 格子熱圖可以用
geom_tile()
繪制。 - 啞鈴圖即是分組散點(diǎn)圖加線段,用
geom_segment()
繪制决侈。 - 將兩個(gè)圖進(jìn)行拼接螺垢,注意拼接比例。
繪制
數(shù)據(jù)格式
示例數(shù)據(jù)是自己隨機(jī)創(chuàng)建的赖歌,無實(shí)際意義枉圃。
Snipaste_2021-10-25_22-46-11
導(dǎo)入并預(yù)處理數(shù)據(jù)
rm(list = ls())
setwd("F:/~/mzbj/mzbj_note/nature_figure1")
data <- read.csv("sample.csv")
df_order <- data[order(data$AFPVALUE),] #排序
df_cell <- data[,c(1,5,6)] #做小熱圖用的數(shù)據(jù)
df2=melt(df_cell,id="SAMPLE") #數(shù)據(jù)變換
#改變level
data$SAMPLE <- factor(data$SAMPLE, levels = df_order$SAMPLE )
df2$SAMPLE <- factor(df2$SAMPLE, levels = df_order$SAMPLE )
df2$variable <- factor(df2$variable,levels = c("MSI","AFP"))
繪制分類變量的格子熱圖
#設(shè)置顏色
cols=c(
"H"="#FE8B91","L"="gray",
"Y"="#FE8B91","N"="gray"
)
p1 <- ggplot(df2,aes(x=SAMPLE,y=variable),size=0.1)+
geom_tile(aes(fill=value),color="white",size=0.1)+
scale_x_discrete("",expand = c(0,0))+
scale_y_discrete("",expand = c(0,0))+
scale_fill_manual(values = cols)+ #指定自定義的顏色
theme(
axis.text.x.bottom = element_blank(),#修改坐標(biāo)軸文本大小
axis.ticks = element_blank(), #不顯示坐標(biāo)軸刻度
legend.title = element_blank() #不顯示圖例title
)
p1
image-20211025225452041
繪制配對(duì)啞鈴圖并添加擬合線
p2 <- ggplot(data) +
geom_segment(aes(
x = SAMPLE,
xend = SAMPLE,
y = value1,
yend = value2
),
color = "#DDEAF6",
size = 0.3) +
geom_point(
aes(x=SAMPLE, y=value1),
group = 1,
color = "#96A6E7",
size = 3
) +
stat_smooth(aes(x = as.numeric(SAMPLE), y = value1),
method=loess,
linetype = 2,
color = '#96A6E7',
fill = '#D9F6F6',
level=0.95) +
geom_point(
aes(x=as.numeric(SAMPLE), y=value2),
color = "#FE8B91",
size = 3
) +
stat_smooth(aes(x = as.numeric(SAMPLE), y = value2),
method=loess,
linetype = 2,
color = '#FE8B91',
fill = '#FEECEA',
level=0.95) +
theme_classic() +
theme(axis.ticks.x = element_blank(),
axis.line.x = element_blank(),
axis.text.x = element_blank())
p2
image-20211025225632153
按比例拼接
library(patchwork)
p1/p2+plot_layout(heights = c(0.1, 1))
image-20211025225752926
基本上還原了這個(gè)圖。圖例部分在AI里進(jìn)行簡(jiǎn)單的修正即可~
不足之處
作者在文章中寫的是用的lasso
曲線進(jìn)行擬合~這里用了loess
方法進(jìn)行擬合庐冯,暫時(shí)還不指導(dǎo)method = glm
時(shí)如何選用lasso
.