- Nature作图也出错:单细胞UMAP/TSNE图的ggplot
- 复现Nature medicine图表---堆叠柱状图显示每个样
- 复现《Nature communications》图表:ggpl
- 复现《nature communications》图表:ggpl
- 复现《nature communications》图表(四):g
- 复现《nature communications》图表(三):画
- 复现《nature communications》图表(二):R
- 复现《nature communications》图表(一):一
- 复现《nature communications》图表(五):G
- 热图如何展示特定行名,缩放单元格大小?
今天复现一篇Nature medicine文章的图表,图大家都很熟悉了,气泡图+聚类,这类图我们在ggplot做热图的时候我们以后实现过了:热图5:ggplot2画热图及个性化修饰。但是为什么这里要复现,不是炒冷饭,肯定是有新东西嘛,不然怎么拿的出手呢?本文作者提供了部分数据和部分代码,他这个图是先用pheatmap做了一个聚类热图,然后利用热图的聚类使用ggplot做的气泡图,最后用AI或者PS修饰组合在一起。其实很多小伙伴觉得在ggplot做聚类不太顺手的话,可以借鉴这个思路,很不错。
![](https://img.haomeiwen.com/i26169980/44c49d63c32cbc4a.png)
(Longitudinal dynamics of clonal hematopoiesis identifies gene-specific fitness effects)第一步,我们先做一个聚类热图:
setwd('D:/KS项目/公众号文章/pheatmap和ggplot的结合')
df <- read.csv('df.csv', header = T)
data <- df[df$PreferredSymbol %in% c("DNMT3A", "TET2", "NOTCH1", "JAK2", "U2AF2", "JAK3", "ASXL1"), ]
data1 <- data[, c("Participant_ID","Largest_VAF","wave","PreferredSymbol")]
#行注释
data.anno <- data1[ , colnames(data1) %in% c("wave", "Participant_ID")]
data.anno <- unique(data.anno)
rownames(data.anno) <- data.anno$Participant_ID
for_order <- reshape2::dcast(as.data.frame(data1),
PreferredSymbol~Participant_ID, value.var="Largest_VAF")
for_order[is.na(for_order)] = 0
rownames(for_order) <- for_order$PreferredSymbol
for_order <- for_order[ , !(colnames(for_order) %in% c("PreferredSymbol")) ]
cluster_order <- pheatmap(for_order, annotation_col = data.anno,
show_rownames = F, show_colnames = F,
annotation_names_col = F)
![](https://img.haomeiwen.com/i26169980/6fa92eeddb16dde0.png)
第二步,做一个气泡图,气泡图的行列排序和热图一样。
#气泡图
p <- ggplot(data, aes(Participant_ID, PreferredSymbol))+
geom_point(aes(size = Largest_VAF,colour = Variant_Classification), alpha=0.3)+
scale_size(range = c(0,15)) +
xlab("") +
ylab("")+theme_minimal() +
theme(panel.background = element_blank(), axis.line = element_line(colour = "black"),
legend.text=element_text(size=11),
axis.text.x = element_blank(),
axis.text.y = element_text(color="black", size=9),
axis.text=element_text(size=16),
axis.title=element_text(size=16, face = "bold"))+
scale_y_discrete(limits=rev(cluster_order$tree_row$labels[cluster_order$tree_row$order]))+
scale_x_discrete(limits=(cluster_order$tree_col$labels[cluster_order$tree_col$order]))+
guides(colour = guide_legend(override.aes = list(size=5),
title = c("Variant Classification")),
size = guide_legend(title = c("VAF")))+
scale_colour_manual(values=c(Frame_Shift_Del="#00BBDA",
Frame_Shift_Ins="#E18A00",
Missense_Mutation="#BE9C00",
Nonsense_Mutation="#24B700",
Splice_Region="#00C1AB",
Splice_Site="#F8766D"))
![](https://img.haomeiwen.com/i26169980/08f2a7fe2fd73669.png)
然后两个修饰组合一下就可以了。觉得分享对你有用的点个赞再走呗!
网友评论