【画图】如何用画热图?

2023-02-28 19:02:54 浏览数 (2)

热图 就是很热的图,会冒火的那种~~~

直接上代码

代码语言:javascript复制
library(pheatmap)
library(RColorBrewer)
library(ggsci)
library(DESeq2)
vsd.T <- vst(dds, blind = FALSE)
#选取差异基因做热图
resSig_P <- subset(res, abs(log2FoldChange)>1 & padj < 0.01)
>mat.1  <- assay(vsd.T.1[rownames(resSig_P), ])
>mat.1  <- mat.1 - rowMeans(mat.1)</p>
#选取区分明显的基因做热图
topVarGenes <- head(order(rowVars(assay(vsd.T)), decreasing = TRUE),1000)
mat  <- assay(vsd.T[ topVarGenes, ])
mat  <- mat - rowMeans(mat)
#设置行列名
anno.1 <- as.data.frame(colData(vsd.T.1)[, c("condition")])
rownames(anno.1) <- colnames(mat.1)
colnames(anno.1) <- c("State")
anno.1_T=subset(anno.1,anno.1$State=="Tumor")
anno.1_N=subset(anno.1,anno.1$State=="Normal")
anno.1<-rbind(anno.1_T,anno.1_N)
mat.1=mat.1[,rownames(anno.1)]
mypal = pal_gsea("default", n = 10, alpha = 0.9)(10)
ann_colors <- list(State=c(Mesenchymal="#756EF8FF",Proneural="#FC7D7FFF"))
pheatmap(mat.1, annotation_col = anno.1,cluster_cols = F,cluster_rows = F,
         show_colnames=F,show_rownames = F, 
         annotation_colors = ann_colors,color = mypal) 
pheatmap(mat, annotation_col = anno.1,cluster_cols = F,cluster_rows = F,
         show_colnames=F,show_rownames = F, 
         annotation_colors = ann_colors,color = mypal) ~~

代码解释

resSig_P <- subset(res, abs(log2FoldChange)>1 & padj < 0.01)这句中res为DESeq2输出的结果,来自于这个:res=result(dds),另外,倍数和padj参数自己看心情调整吧topVarGenes <- head(order(rowVars(assay(vsd.T)), decreasing = TRUE),1000)这句中1000这个数字自己看心情调整吧mat <- mat - rowMeans(mat)这句就是热图中数值标准化算法,当然还有别的,想DIY自己去google吧anno.1 <- as.data.frame(colData(vsd.T.1)[, c("condition")])这句中"condition"的condition就是DESeq2准备的coldata中那个列名,这个名字错了会错pheatmap(mat.1, annotation_col = anno.1,cluster_cols = F,cluster_rows = F,show_colnames=F,show_rownames = F, annotation_colors = ann_colors,color = mypal) 这句中所有的F都可以改成T,F就是关闭,T就是打开比如列聚类打开cluster_cols=T,行聚类打开cluster_rows =T显示列名show_colnames=T,显示行名show_rownames = Trownames(anno.1) <- colnames(mat.1)colnames(anno.1) <- c("State")anno.1_T=subset(anno.1,anno.1State=="Tumor")anno.1_N=subset(anno.1,anno.1

0 人点赞