写在前面
【这图怎么画】系列的图都来自VIP群
里同学的提问。推文只是对图片的复现,不代表作者对图片展现形式的认同。欢迎同学们在群里分析有意思的图片。
本期图片
ML-heatmap
❝VIP群里同学的提问,图片来源未知,很显然相较于图片的绘制,本图的数据来源才是难点。基本思路就是:模型+循环,这里就先按下不表。本篇推文还是简单来画个图。
❞
复现结果
result
示例数据和代码领取
绘图
library(RColorBrewer) library(ComplexHeatmap) ## sample model_data <- data.frame(row.names = paste0('model',1:20), data1 = runif(20,0.55,0.90), data2 = runif(20,0.55,0.85), data3 = runif(20,0.55,0.85), data4 = runif(20,0.55,0.85)) ## 平均C-index mean <- apply(model_data, 1, mean) mean_sort <- sort(mean, decreasing = T) model_data <- model_data[names(mean_sort), ] ## plot ### barplot row_bar = rowAnnotation(bar = anno_barplot(mean_sort, bar_width = 0.8, border = FALSE, gp = gpar(fill = "#aa9b81", col = NA), add_numbers = F, # 不显示数字 width = unit(2, "cm")), show_annotation_name = F) ### top annotation CohortCol <- c('#bc492f','#316da8','#428458','#7c76b0') # 设置队列颜色 names(CohortCol) <- colnames(model_data) col_title = columnAnnotation("Cohort" = colnames(model_data), col = list("Cohort" = CohortCol), show_annotation_name = F) hm <- Heatmap(as.matrix(model_data), name = "C-index", right_annotation = row_bar, top_annotation = col_title, col = c("#58aaa1", "#FFFFFF", "#e7bc6a"), rect_gp = gpar(col = "gray", lwd = 1), cluster_columns = FALSE, cluster_rows = FALSE, show_column_names = FALSE, show_row_names = TRUE, row_names_side = "left", column_split = factor(colnames(model_data), levels = colnames(model_data)), column_title = NULL, heatmap_legend_param = list( border = 'black' ), cell_fun = function(j, i, x, y, w, h, col) { # add text to each grid grid.text(label = format(model_data[i, j], digits = 3, nsmall = 3), x, y, gp = gpar(fontsize = 10)) } ) ## save pdf("Cindex.pdf", width = 6, height = 7) draw(hm) invisible(dev.off())
往期内容
- 资源汇总 | 2022 木舟笔记原创推文合集(附数据及代码领取方式)
- CNS图表复现|生信分析|R绘图 资源分享&讨论群!
- R绘图 | 浅谈散点图及其变体的作图逻辑
- 这图怎么画| 有点复杂的散点图
- 这图怎么画 | 相关分析棒棒糖图
- 组学生信| Front Immunol |基于血清蛋白质组早期诊断标志筛选的简单套路
- (免费教程+代码领取)|跟着Cell学作图系列合集
- Q&A | 如何在论文中画出漂亮的插图?
- 跟着 Cell 学作图 | 桑葚图(ggalluvial)
- R实战 | Lasso回归模型建立及变量筛选
- 跟着 NC 学作图 | 互作网络图进阶(蛋白+富集通路)(Cytoscape)
- R实战 | 给聚类加个圈圈(ggunchull)
- R实战 | NGS数据时间序列分析(maSigPro)
- 跟着 Cell 学作图 | 韦恩图(ggVennDiagram)