复现nature medicine图表:pheatmap结合ggplot

今天复现一篇Nature medicine文章的图表,图大家都很熟悉了,气泡图+聚类,这类图我们在ggplot做热图的时候我们以后实现过了:热图5:ggplot2画热图及个性化修饰但是为什么这里要复现,不是炒冷饭,肯定是有新东西嘛,不然怎么拿的出手呢?本文作者提供了部分数据和部分代码,他这个图是先用pheatmap做了一个聚类热图,然后利用热图的聚类使用ggplot做的气泡图,最后用AI或者PS修饰组合在一起。其实很多小伙伴觉得在ggplot做聚类不太顺手的话,可以借鉴这个思路,很不错。

(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)

image.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"))

然后两个修饰组合一下就可以了。觉得分享对你有用的点个赞再走呗!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值