准备数据
① 表达矩阵(按照分型排序好)
② 构建临床分组数据
Cancer <- exp[rownames(group_data[which(group_data$tissue == "Cancer"),]),] # Cancer 根据自己的需求更换
Normal <- exp[rownames(group_data[which(group_data$tissue == "Normal"),]),] # Normal 根据自己的需求更换
A <- as.data.frame(t(rbind(Cancer,Normal))) # 按照顺序,重新组合样本
# 单组分组信息
annotation_col = data.frame(
group = c(rep("Cancer",10),rep("Normal",10)
#,Gender = c(rep("F",9),rep("M",9))
))
row.names(annotation_col) <- colnames(A)
groupcolor <- c("#922927","#85B22E") # 颜色
names(groupcolor) <- c("Cancer","Normal") #类型一一对应
# 多单个分组信息
#Gendercolor <- c("red","#016D06")
#names(Gendercolor) <- c("F","M") #类型颜色
ann_colors <- list(group=groupcolor) #颜色设置 单组
#ann_colors <- list(group=groupcolor,Gender = Gendercolor) # 多组
#在画图的时候,heatmap函数中多添加annotation_colors即可:
pheatmap(A,cluster_rows = T,cluster_cols = F,
color=colorRampPalette(c("navy","white","firebrick3"))(100),
show_colnames = F,border_color = NA,scale = "row",show_rownames =T,
annotation_col = annotation_col,
annotation_colors = ann_colors)
dev.off()
效果图: