热图

2021-06-08  本文已影响0人  学习生信的小兔子
rm(list = ls())

library(readr)
library(plyr)
library(readxl)
library(RColorBrewer)
library(pheatmap)
matrix<-read.table("proteomic_matrix.txt",header = T,sep = "\t",row.names = 1) 
matrix[is.na(matrix)] <- 0 #给空值赋0

info<-read_excel("sampleinfo.xlsx") #导入分组信息

annotation_col<- data.frame(type = info$Type,  # 构建行注释信息
                            sex=info$Sex,
                            age=info$Age,
                            row.names = info$TMT)

type_color <- c("#85B22E","#5F80B4","#E29827","#922927") 
names(type_color) <- c("jkdz","jbdz","PT","ZX") #类型颜色

sex_color <- c("red","#016D06")
names(sex_color) <- c("F","M") #性别颜色

ann_colors <- list(type=type_color,sex=sex_color) #颜色设置

matrix_2<-data.frame(scale(matrix,center = T)) #中心化
#绘制热图
pheatmap(matrix_2,
         scale="row",#对行进行归一化
         color = colorRampPalette(c("blue", "white","red" ))(1000), # color参数自定义颜色
         annotation_col = annotation_col,
         annotation_colors = ann_colors, 
         fontsize_col = 10, 
         cluster_rows = T,# cluster_row = FALSE参数设定对行进行聚类 
         cluster_cols = F,
         show_rownames =T, # show_rownames和show_colnames参数设定是否显示行名和列名
         show_colnames = F,
         fontsize = 5,
         cellwidth=5,
         cellheight=5, # cellwidth和cellheight参数设定每个热图格子的宽度和高度
         main = "Heatmap") # main参数添加主标题

有点小瑕疵 参考:木舟笔记

上一篇 下一篇

猜你喜欢

热点阅读