跟著高分SCI學(xué)作圖 -- 復(fù)雜熱圖+漸變色連線

封面

從這個(gè)系列開(kāi)始,師兄就帶著大家從各大頂級(jí)期刊中的Figuer入手,從仿照別人的作圖風(fēng)格到最后實(shí)現(xiàn)自己游刃有余的套用在自己的分析數(shù)據(jù)上!這一系列絕對(duì)是高質(zhì)量!還不趕緊點(diǎn)贊+在看,學(xué)起來(lái)!

本期分享的是期刊:J Am Soc Nephrol上面一篇文章中的一個(gè)復(fù)雜熱圖+漸變色連線!

示例數(shù)據(jù)和代碼獲取

生信常用分析圖形+跟著高分SCI學(xué)作圖

參考文獻(xiàn)

話不多說(shuō),直接上圖!

讀圖

原圖

效果展示

復(fù)現(xiàn)效果

示例數(shù)據(jù)完全虛擬構(gòu)建,無(wú)實(shí)際意義!此外這次的圖形在AI中進(jìn)行了細(xì)微的調(diào)整,代碼復(fù)現(xiàn)后,大家也可以手動(dòng)嘗試一下!

數(shù)據(jù)構(gòu)建

library(ggplot2)
library(ComplexHeatmap)
library(ggforce)

# 構(gòu)建示例數(shù)據(jù):
LU_matrix <- matrix(runif(70, 0, 0.5), nrow = 10, ncol = 7)
RD_matrix <- matrix(runif(105, -0.5, 0), nrow = 15, ncol = 7)
RU_matrix <- matrix(runif(30, -0.5, 0), nrow = 10, ncol = 3)
LD_matrix <- matrix(runif(45, 0, 0.5), nrow = 15, ncol = 3)

data <- rbind(cbind(LU_matrix, RU_matrix), cbind(RD_matrix, LD_matrix))
rownames(data) <- paste0("gene", 1:nrow(data))
colnames(data) <- paste0("sample", 1:ncol(data))

data[1:5, 1:5]
#         sample1    sample2    sample3    sample4    sample5
# gene1 0.3131575 0.25730166 0.16792109 0.01307018 0.30757497
# gene2 0.0686659 0.02419527 0.21418035 0.43881553 0.17062910
# gene3 0.2613189 0.36180567 0.26212484 0.25380708 0.02827532
# gene4 0.4033809 0.49797550 0.09943902 0.09800037 0.42676588
# gene5 0.4266993 0.09472528 0.04880730 0.17731476 0.19154542

熱圖

# 設(shè)置顏色:
library(circlize)
col_fun <- colorRamp2(c(-0.5, 0, 0.5), c("#04a3ff", "#ffffff","#ff349c"))

# 繪制熱圖:
# 由于只是示例,左右采用相同的矩陣:
p1 <- Heatmap(data, 
        # 設(shè)置顏色:
        col = col_fun,
        # 調(diào)整熱圖格子的邊框顏色和粗細(xì):
        rect_gp = gpar(col = "white", lwd = 1),
        # 去掉聚類樹(shù):
        cluster_columns = F, 
        cluster_rows = F,
        # show_row_dend = F,
        # show_column_dend = F,
        # 列標(biāo)題旋轉(zhuǎn)角度:
        column_names_rot = -45,
        # 添加文字
        cell_fun = function(j, i, x, y, width, height, fill) {
          grid.text(sprintf("%.2f", data[i, j]), x, y, gp = gpar(fontsize = 5))},
        # 去掉圖例:
        show_heatmap_legend = F
        )

# 繪制熱圖:
# 由于只是示例,左右采用相同的矩陣:
p2 <- Heatmap(data, 
              # 設(shè)置顏色:
              col = col_fun,
              # 調(diào)整熱圖格子的邊框顏色和粗細(xì):
              rect_gp = gpar(col = "white", lwd = 1),
              # 去掉聚類樹(shù):
              cluster_columns = F, 
              cluster_rows = F,
              # show_row_dend = F,
              # show_column_dend = F,
              # 列標(biāo)題旋轉(zhuǎn)角度:
              column_names_rot = 45,
              # 添加文字
              cell_fun = function(j, i, x, y, width, height, fill) {
                grid.text(sprintf("%.2f", data[i, j]), x, y, gp = gpar(fontsize = 5))},
              # 去掉圖例:
              show_heatmap_legend = F,
              # 行名靠左:
              row_names_side = "left"
)
熱圖

基因連線

# 構(gòu)建基因連線數(shù)據(jù):
lines <- data.frame(
  x = as.character(c(rep(1, 25),rep(2,25))),
  y = c(sample(1:25), sample(1:25)),
  group = rep(1:25, 2)
)

p3 <- ggplot(lines) +
  geom_link2(aes(x = x, y = y, group = group,
                colour = stat(index)
                ), size = 2)+
  scale_colour_gradient2(low = "#04a3ff", mid = "#ffffff", high = "#ff349c", 
                         midpoint = 0.5)+
  geom_point(aes(x, y, group = group, fill = x), shape = 21, color = "#fc1e1e", size = 4)+
  scale_fill_manual(values = c("#04a3ff", "#ff349c"))+
  # 空白主題:
  theme_minimal() + 
  theme(
    legend.position = "none",
    axis.title.x = element_blank(),
    axis.title.y = element_blank(),
    panel.border = element_blank(),
    panel.grid=element_blank(),
    axis.ticks = element_blank(),
    axis.text = element_blank(),
    plot.title=element_text(size=0, face="bold")
  ) 

image-20220727162807564.png

拼圖

# 拼圖
library(patchwork)
library(ggplotify)

layout <- c(
  area(t = 1, l = 1, b = 6, r = 3),
  area(t = 1, l = 3, b = 6, r = 7),
  area(t = 1, l = 7, b = 6, r = 9)
)

as.ggplot(p1) + p3 + as.ggplot(p2) + plot_layout(design = layout)

ggsave("heatmap.pdf",height = 8, width = 12)

結(jié)果展示

結(jié)果展示

示例數(shù)據(jù)和代碼獲取

生信常用分析圖形+跟著高分SCI學(xué)作圖

以上就是本期的全部?jī)?nèi)容啦!歡迎點(diǎn)贊,點(diǎn)在看!師兄會(huì)盡快更新哦!制作不易,你的打賞將成為師兄繼續(xù)更新的十足動(dòng)力!

往期文章

  1. 跟著Nature Medicine學(xué)作圖--箱線圖+散點(diǎn)圖
  2. 跟著Nature Communications學(xué)作圖--漸變火山圖
  3. 跟著Nature Communications學(xué)作圖--氣泡圖+相關(guān)性熱圖
  4. 跟著Nature Communications學(xué)作圖 -- 復(fù)雜提琴圖
  5. 跟著Nature Communications學(xué)作圖 -- 復(fù)雜熱圖
  6. 跟著Nature Communications學(xué)作圖--復(fù)雜散點(diǎn)圖
  7. 跟著Nature Communications學(xué)作圖 -- 復(fù)雜百分比柱狀圖
  8. 跟著Molecular Cancer學(xué)作圖 -- 分半小提琴圖
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容