ggplot集锦

挑选ssGSEA的基因集绘制基因热图

2022-11-09  本文已影响0人  CrimsonUMO

首先加载相应的包

library(pheatmap)
library(msigdbr)

然后找到感兴趣的通路的基因集

m_df = msigdbr(
  species = "Mus musculus", 
  category = "H")
m_list = m_df %>% split(x = .$gene_symbol, f = .$gs_name)
names(m_list)
m_list[[26]]#INF-α
m_list[[27]]#INF-β

读取TPM格式的数据

load("./tpms.rdata")

准备好分组信息

annotation_col = data.frame(group = substr(colnames(tpms),1,3))
rownames(annotation_col) <- colnames(tpms)
annotation_col$group <- factor(annotation_col$group,levels = c('NL',"CON","XHW"))

准备绘图用的数据

plot <- tpms[which(rownames(tpms)%in%m_list[[num]]),]
plot <- log2(plot+1)
plot <- scale(plot)
#plot[plot < -2] <- -2
#plot[plot > 2] <- 2
#这两条也可以不执行

指定绘图用的颜色并绘制热图

col <- colorRampPalette(c("navy", "white", "firebrick3"))(100)
p <- pheatmap(plot,
         show_colnames = T,
         cluster_rows = T,
         cluster_cols = F,
         annotation_col = annotation_col,
         color = col,
         #breaks=bk,
         cellwidth=5,
         scale = 'row',
         cellheight=5,
         #filename = './ssGSEA/INF-α.png',
         fontsize=5
         )
png(width = 961,height = 2160,res = 300,filename = './ssGSEA/INF-α.png')
print(p)
dev.off()
上一篇 下一篇

猜你喜欢

热点阅读