生信图可视化大全

零基础R语言绘制热图

2019-10-23  本文已影响0人  亮亮就是亮

第一步安装:

install.packages("pheatmap") #安装pheatmap包
install.packages("RColorBrewer") #安装RColorBrewer包
library(pheatmap) #加载pheatmap包
library(RColorBrewer) #加载RColorBrewer包

这里稍微给大家介绍一下RColorBrewer包:

RColorBrewer is an R package that allows users to create colourful graphs with pre-made color palettes.

为什么要使用它,是因为他艳丽及丰富的配色深深的把小编吸引住了,这么好的东西一定要分享给大家。他有三个配色。大家可以根据情况使用。

image image image

第二步读取数据:

首先我们来看一下数据的格式,第一行为样品名称,第一列为基因名称。

image
fitness <- read.delim("C:/Users/dell/Desktop/fitness.txt", row.names = 1) #读取数据
id <- read.delim("C:/Users/dell/Desktop/id.tmp") #读取需要画图的基因
fit.sel <- fitness[which(rownames(fitness) %in% id$ID), ] #提取需要画图的数据并保存 

第三步查看数据分布:

summary(fit.sel)  #查看数据最大值最小值设置scale范围

第四步画图:

bk = unique(c(seq(-5, 0, length=100), seq(0, 2, length=100))) #scale范围
col = c(colorRampPalette(rev(brewer.pal(11, "RdYlBu")))(200)) #颜色选取RdYlBu
pheatmap(fit.sel, color = col, breaks = bk, show_rownames = T, clustering_method = "ward.D2")```

最后查看结果:

image

最后总结一下常用参数的设置:

treeheight_row 设置row方向的聚类树高
treeheight_col 设置col方向的聚类树高
cellheight 表示每个单元格的高度
cellwidth 表示每个单元格的宽度
display_numbers 表示是否将数值显示在热图的格子中(T/F)。
fontsize 表示热图中字体显示的大小
number_color 设置显示内容的颜色

pheatmap(fit.sel, cellheight=9, cellwidth=18, treeheight_row=100, treeheight_col=18, 
          color = col, breaks = bk, show_rownames = T, display_numbers=T, 
          number_color="black", fontsize=6, clustering_method = "ward.D2")

这样运行的结果如下:

image

欢迎关注公众号:"生物信息学"

上一篇下一篇

猜你喜欢

热点阅读