pheatmap热图绘制
2021-01-22 本文已影响0人
生信小书生
欢迎关注微信公众号“生信小书生”!
Heatmap是以颜色的变化来反映二维矩阵或表格中的数据信息,它可以直观地将数据值的大小以定义的颜色深浅直观的表示出来。今天我们带大家展示一下,如何绘制一幅漂亮的热图。
一、前期准备
首先,需要安装绘制热图所需要的包-packages "pheatmap"
rm(list=ls())#清除环境变量
install.packages("pheatmap")#下载包
library(pheatmap)#加载pheatmap包
二、载入路径
根据个人需要,载入当前存放文件的路径
getwd()#查看当前路径
setwd("D:/生信小书生/R语言绘图/2021-1-20热图")#读入当前路径
三、读入数据
根据文件的相应格式,选择不同的函数,读入即将呈现的数据,由于绘制需要我们这里使用三组数据data1,data2,data3
data1 <- read.table("pheatmap.xlsx",header = T,row.names = 1,stringsAsFactors = F)
data1

data2 <- read.delim2("an_row.txt",header = T,row.names = 1,stringsAsFactors = F)

data3 <- read.delim2("an_col.txt",header = T,row.names = 1,stringsAsFactors = F)

四、绘图
pheatmap(data1)#基本绘图

pheatmap(data1,annotation_row = data2,annotation_col = data3)#添加行列注释信息

pheatmap(data1,annotation_row = data2,annotation_col = data3,scale ="row" )#按照行聚类

#给图例换色an_colors <- list(Virus=c(A="#32CD32",B="#FFA500",C="#FF1493",D="#00BFFF",E="#00FFFF",G="#40E0D0",H="#006400",I="#FF4500",
K ="#FF0000",J="#BC8F8F"),#给行添加注释添加颜色
Country=c(USA="#00FA9A",CA="#3CB371"))#给列添加注释添加颜色
pheatmap(data1,annotation_row = data2,annotation_col = data3,scale ="row",annotation_colors = an_colors )#按照列聚类

pheatmap(data1,annotation_row = data2,annotation_col = data3,#添加行列注释信息
cutree_rows = 2,cutree_cols =10, #将行分为两类,列分为10类
annotation_colors = an_colors,#给分类添加注释
cellwidth =12,cellheight = 10 ,#调整细胞(小格子)大小
scale ="row" ,#按照列聚类
main="my heatmap",#给图添加标题
angle_col =45)#给横轴字体添加角度

欢迎关注微信公众号“生信小书生”,免费领取操作数据!