❝已经付费加群的小伙伴无需二次付费,等待师兄后续更新即可!
❞
![d288e334129211bd698fddf619fd9618.png](https://img-blog.csdnimg.cn/img_convert/d288e334129211bd698fddf619fd9618.png)
从这个系列开始,师兄就带着大家从各大顶级期刊中的Figuer入手,从仿照别人的作图风格到最后实现自己游刃有余的套用在自己的分析数据上!这一系列绝对是高质量!还不赶紧「点赞+在看」,学起来!
❝本期分享的是期刊:「Nature Communication」上面一篇文章中的一个「复杂热图+堆积柱状图」!
本系列所有代码和示例数据将会和生信常用图形系列绘图放在一起,公众号右下角添加师兄微信,「付费149元」,即可加入生信绘图交流群。「群内不仅提供生信常用图形系列的代码,还会提供本系列后续所有Figure的实例数据和代码,我会在文章更新后第一时间上传。」
当然了!如果你还想白嫖,师兄的文章中代码已经写的很清楚了!但是师兄还是希望你点个赞再走呗!
以上就是本期的全部内容啦!「欢迎点赞,点在看!」师兄会尽快更新哦!制作不易,你的打赏将成为师兄继续更新的十足动力!
「优惠方式:点赞+在看,并转发这两个系列任意一篇文章至朋友圈,集赞20个,即可享受¥119入群!」
❞
![1355a5e779820a2ec998efcc879ac8a0.png](https://img-blog.csdnimg.cn/img_convert/1355a5e779820a2ec998efcc879ac8a0.png)
话不多说,直接上图!
读图
![93c5bc3eaf32d347ac5b6f1830879267.png](https://img-blog.csdnimg.cn/img_convert/93c5bc3eaf32d347ac5b6f1830879267.png)
效果展示
![2b487aecc34ec5826cc72d6aec1c3a7c.png](https://img-blog.csdnimg.cn/img_convert/2b487aecc34ec5826cc72d6aec1c3a7c.png)
❝本期示例数据为文章附件,大家可以通过以下链接下载:
https://static-content.springer.com/esm/art%3A10.1038%2Fs41467-022-31780-9/MediaObjects/41467_2022_31780_MOESM9_ESM.xlsx
由于
❞ComplexHeatmap
包自带的rowAnnotation
柱状图注释效果有限,所以这里师兄用ggplot2
绘制了左侧的堆积柱状图,最后用AI将两者拼接在一起!大家也可以自己尝试用ComplexHeatmap
绘制,但是效果可能没这个好看。
R包载入和数据预处理
library(xlsx)
library(ComplexHeatmap)
library(tidyverse)
library(ggplot2)
library(circlize)
library(patchwork)
library(ggplotify)
# 读取文章附件数据:
data <- read.xlsx("41467_2022_31780_MOESM9_ESM.xlsx", sheetIndex = 1)
data <- data[-c(1:2), ]
colnames(data) <- data[1,]
data <- data[-1,]
# 数据预处理:
data_mat <- as.data.frame(table(data$Gene, data$`Abbreviation of Tumor Type`)) %>%
pivot_wider(names_from = Var2, values_from = Freq) %>%
column_to_rownames("Var1")
data_mat <- data_mat[,order(colSums(data_mat), decreasing = T)]
data_mat <- data_mat[order(rowSums(data_mat), decreasing = T),]
data_mat2 <- as.matrix(data_mat)
data_mat2[which(data_mat2 == 0)] <- NA
热图
# 基础热图:
Heatmap(data_mat2,
na_col = "white",
# 去掉行列聚类:
cluster_rows = F,
cluster_columns = F)
# 修改颜色+添加文字和描边
col_fun = colorRamp2(c(0, 5, 10, 15), c("#b4d9e5", "#91a1cf", "#716bbf","#5239a3"))
p1 <- Heatmap(data_mat2,
col = col_fun,
na_col = "white",
# 去掉行列聚类:
cluster_rows = F,
cluster_columns = F,
row_names_side = "left",
# 图例
heatmap_legend_param = list(
title = "Frequency(%)",
title_position = "leftcenter",
legend_direction = "horizontal"
),
# 行名和列名:
row_names_gp = gpar(fontsize = 10, font = 3),
column_names_gp = gpar(fontsize = 10, font = 3),
# 添加文字注释:
cell_fun = function(j, i, x, y, width, height, fill) {
if (!is.na(data_mat2[i,j])) {
grid.text(sprintf("%1.f", data_mat2[i, j]), x, y,
gp = gpar(fontsize = 10, col = "#df9536"))
grid.rect(x, y, width, height,
gp = gpar(col = "grey", fill = NA, lwd = 0.8))
}
})
pdf("Heatmap.pdf", height = 8, width = 8)
draw(p1, heatmap_legend_side = "bottom")
dev.off()
![e592b74cebccb551e08afd016c9a2c62.png](https://img-blog.csdnimg.cn/img_convert/e592b74cebccb551e08afd016c9a2c62.png)
堆积柱状图
# 添加左侧堆积柱状图:
data_mat3 <- as_tibble(data_mat/rowSums(data_mat)) %>%
pivot_longer(cols = everything(), names_to = "CancerType",
values_to = "value")
data_mat3$Gene <- factor(rep(rownames(data_mat), each = 21),
levels = rev(rownames(data_mat)))
p2 <- ggplot(data_mat3)+
geom_bar(aes(x = Gene, y = value, fill = CancerType),
position = "stack", stat = "identity")+
scale_y_continuous(labels = seq(0,100,25),position = "right")+
ggsci::scale_fill_igv()+
ylab("Percentage(%)")+
theme_bw()+
theme(panel.grid = element_blank(),
axis.title.y = element_blank(),
axis.text.y = element_blank(),
axis.ticks.y = element_blank(),
axis.title.x = element_text(face = "bold"),
legend.position = "bottom",
legend.key.size = unit(0.3, 'cm'),
legend.title=element_text(face="bold")
)+
labs(fill = "Tumor Type")+
guides(fill = guide_legend(title.position = "top",
title.hjust = 0.5, ncol = 2,
byrow = TRUE))+
coord_flip()
p2
ggsave("Stack_Barplot.pdf", height = 8, width = 1.5)
![b34bb41db4956b33473edf5c15c583eb.png](https://img-blog.csdnimg.cn/img_convert/b34bb41db4956b33473edf5c15c583eb.png)
AI拼图效果展示
![56fb4745c88da7995ade3ebefcfc9823.png](https://img-blog.csdnimg.cn/img_convert/56fb4745c88da7995ade3ebefcfc9823.png)
往期优秀图形目录
![fabb37352350d50732d4031f33cb42f5.png](https://img-blog.csdnimg.cn/img_convert/fabb37352350d50732d4031f33cb42f5.png)
![f8a2de58db957549693b2a538047ef51.png](https://img-blog.csdnimg.cn/img_convert/f8a2de58db957549693b2a538047ef51.png)
![c48217092dffef6f7d4047cce325e093.png](https://img-blog.csdnimg.cn/img_convert/c48217092dffef6f7d4047cce325e093.png)
![6c9741aeff66561bd5d2ddc4d7bd6dec.png](https://img-blog.csdnimg.cn/img_convert/6c9741aeff66561bd5d2ddc4d7bd6dec.png)
![87a49128e856466f3d69365a8f48ceca.png](https://img-blog.csdnimg.cn/img_convert/87a49128e856466f3d69365a8f48ceca.png)
![2f340fb9977ba2e04713c1eb1797387d.png](https://img-blog.csdnimg.cn/img_convert/2f340fb9977ba2e04713c1eb1797387d.png)
![435172e4cce76e29692e09f16b94b74a.png](https://img-blog.csdnimg.cn/img_convert/435172e4cce76e29692e09f16b94b74a.png)
![8fd694f88934a23644e33e94d3c38d0a.png](https://img-blog.csdnimg.cn/img_convert/8fd694f88934a23644e33e94d3c38d0a.png)
![3f81974b28a9b6a0553f4578f475e9e9.png](https://img-blog.csdnimg.cn/img_convert/3f81974b28a9b6a0553f4578f475e9e9.png)
![3f0bf2afb43bdf5d9aeab5ad4a95c3b7.png](https://img-blog.csdnimg.cn/img_convert/3f0bf2afb43bdf5d9aeab5ad4a95c3b7.png)
![456e79f709655a98a86eb3215219cc3c.png](https://img-blog.csdnimg.cn/img_convert/456e79f709655a98a86eb3215219cc3c.png)
![fa89dc48f41fa67bc5daa5b9525354c4.png](https://img-blog.csdnimg.cn/img_convert/fa89dc48f41fa67bc5daa5b9525354c4.png)
![d80f90c786e1e435aed6e1fdcd956417.png](https://img-blog.csdnimg.cn/img_convert/d80f90c786e1e435aed6e1fdcd956417.png)
![3e63a2e54cb223bc82252d14f5c8d6a3.png](https://img-blog.csdnimg.cn/img_convert/3e63a2e54cb223bc82252d14f5c8d6a3.png)
![ac610c1880b98436c6f672d61c2e6849.png](https://img-blog.csdnimg.cn/img_convert/ac610c1880b98436c6f672d61c2e6849.png)
❝以上内容仅为群内部分内容,不代表全部。详细目录请看下方列表!已经入群的小伙伴,无需付费购买推文,群内都会及时更新!
❞
示例数据和代码获取
❝本系列「所有代码和示例数据将会和生信常用图形系列绘图」放在一起,公众号右下角添加师兄微信,「付费149元,即可加入生信绘图交流群」。群内不仅提供生信常用图形系列的代码,还会「提供本系列后续所有Figure的示例数据和代码」,我会在文章更新后第一时间上传。
当然了!如果你还想白嫖,师兄的文章中代码已经写的很清楚了!但是师兄还是希望你「点个赞再走」呗!
以上就是本期的全部内容啦!「欢迎点赞,点在看」!师兄会尽快更新哦!制作不易,你的打赏将成为师兄继续更新的十足动力!
「优惠方式:点赞+在看,并转发这两个系列任意一篇文章至朋友圈,集赞20个,即可享受¥119入群!」
❞
往期文章
跟着Nature Communications学作图 -- 甘特图