R语言 绘制热图 pheatmap

9 篇文章 1 订阅
5 篇文章 0 订阅
### 安装软件包
install.packages("pheatmap")
install.packages("vegan")


### 加载所需软件包
library(pheatmap)
library(gplots)
library(vegan)
library(permute)
library(lattice)




path <- "C:/Users/yuki_cool/RWorkspace/progess.csv"


#data<-read.csv(path, sep=",")
data<-read.table(path, header = T, sep ="\t", row.names = 1)
data<-read.table(path, header = T, sep =",", row.names = 1)
data_matrix<-as.matrix(data)


pheatmap(data_matrix, color = heat.colors(256))
heatmap.2(data_matrix, Rowv = NA , Colv = 2)
heatmap(data_matrix, Rowv = 1,  Colv=1)




#mycolors <- colorRampPalette(c("blue", "white", "darkgreen", "yellow", "orangered"), bias=1.2)(n)
#barplot(rep(1,times=n), col=mycolors, border=mycolors, axes=FALSE); box()


mycolors <- colorRampPalette(c("black", "green", "red"), bias = 1.2)(100)
heatmap(data_matrix, Rowv=NA, Colv=NA, col= mycolors, legend = TRUE, revC=FALSE, scale="column")


drows<-vegdist(data_matrix, method ="bray")
dcols<-vegdist(t(data_matrix), method ="bray")


pdf(file ="heatmap1.pdf", width = 10, height = 10)
# scale   legend 的 范围 


############# clustering_method ##############################################
#the agglomeration method to be used. 
#This should be (an unambiguous abbreviation of) one of "ward.D", "ward.D2",
# "single", "complete", "average" (= UPGMA), "mcquitty" (= WPGMA),
#"median" (= WPGMC) or "centroid" (= UPGMC).
##############################################################################
pheatmap(data_matrix,cellwidth = 20, cellheight = 20, treeheight_row = 20,cluster_cols = FALSE,
      color = colorRampPalette(c("green", "black","red"))(1000),
          legend = FALSE, border_color = NA, fontsize_row = 10,scale = TRUE,
         fontsize_col = 10,ColSideColors = heat.colors(12), clustering_method ="ward.D", main ="Sorce")

官方文档:

Version:1.0StartHTML:0000000107 EndHTML:0000026487 StartFragment:0000000127EndFragment:0000026469
pheatmap {pheatmap}
R Documentation
A function to draw clustered heatmaps.

Description

A function to draw clustered heatmaps where one has better controlover some graphical parameters such as cell size, etc.
Usage

pheatmap(mat, color = colorRampPalette(rev(brewer.pal(n = 7, name =
“RdYlBu”)))(100), kmeans_k = NA, breaks = NA, border_color = “grey60”,
cellwidth = NA, cellheight = NA, scale = “none”, cluster_rows = TRUE,
cluster_cols = TRUE, clustering_distance_rows = “euclidean”,
clustering_distance_cols = “euclidean”, clustering_method = “complete”,
clustering_callback = identity2, cutree_rows = NA, cutree_cols = NA,
treeheight_row = ifelse((class(cluster_rows) == “hclust”) || cluster_rows,
50, 0), treeheight_col = ifelse((class(cluster_cols) == “hclust”) ||
cluster_cols, 50, 0), legend = TRUE, legend_breaks = NA,
legend_labels = NA, annotation_row = NA, annotation_col = NA,
annotation = NA, annotation_colors = NA, annotation_legend = TRUE,
annotation_names_row = TRUE, annotation_names_col = TRUE,
drop_levels = TRUE, show_rownames = T, show_colnames = T, main = NA,
fontsize = 10, fontsize_row = fontsize, fontsize_col = fontsize,
display_numbers = F, number_format = “%.2f”, number_color = “grey30”,
fontsize_number = 0.8 * fontsize, gaps_row = NULL, gaps_col = NULL,
labels_row = NULL, labels_col = NULL, filename = NA, width = NA,
height = NA, silent = FALSE, …)
Arguments

mat
数值矩阵
color
mycolors <- colorRampPalette(c(“black”,”green”,”red”), bias = 1.2)(100);
redgreen(75)

预设的五个调色板:rainbow
heat.colors
terrain.colors
topo.colors
Cm.colors
Exp: heat.colors(256)

kmeans_k
the number of kmeans clusters to make, if we want to agggregate the rows before drawing heatmap. If NA then the rows are not aggregated.
breaks
a sequence of numbers that covers the range of values in mat and is one element longer than color vector. Used for mapping values to colors. Useful, if needed to map certain values to certain colors, to certain values. If value is NA then the breaks are calculated automatically.
border_color
单元格边界颜色
cellwidth
单元格从宽度
cellheight
单元格高度
scale
归一化,Corresponding values are “row”, “column” and”none”
cluster_rows
按列聚类分析 TRUE or FALSE
cluster_cols
按横聚类分析 TRUE or FALSE
clustering_distance_rows
列聚类分析 euclidean”, “maximum”, “manhattan”,”canberra”, “binary” or “minkowski”

clustering_distance_cols
….
clustering_method
使用聚类的方法: “ward.D”,”ward.D2”, “single”, “complete”, “average” (= UPGMA), “mcquitty” (= WPGMA),”median” (= WPGMC) or “centroid” (= UPGMC).

clustering_callback
callback function to modify the clustering. Is called with two parameters: original hclustobject and the matrix used for clustering. Must return a hclust object.
cutree_rows
根据聚类分析 按行数分开
cutree_cols
。。。。
treeheight_row
树的高度,默认50
treeheight_col
树的高度,默认50
legend
图例
legend_breaks
vector of breakpoints for the legend.
legend_labels
vector of labels for the legend_breaks.
annotation_row
data frame that specifies the annotations shown on left side of the heatmap. Each row defines the features for a specific row. The rows in the data and in the annotation are matched using corresponding row names. Note that color schemes takes into account if variable is continuous or discrete.
annotation_col
annotation_col = data.frame(factor(GeneClass = rep(“Gene1”,”Gene 2”), c(2, 3)))
annotation
deprecated parameter that currently sets the annotation_col if it is missing
annotation_colors
list for specifying annotation_row and annotation_col track colors manually. It is possible to define the colors for only some of the features. Check examples for details.
annotation_legend
boolean value showing if the legend for annotation tracks should be drawn.
annotation_names_row
boolean value showing if the names for row annotation tracks should be drawn.
annotation_names_col
boolean value showing if the names for column annotation tracks should be drawn.
drop_levels
logical to determine if unused levels are also shown in the legend
show_rownames
横名
show_colnames
列名
main
图片标题
fontsize
base fontsize for the plot
fontsize_row
fontsize for rownames (Default: fontsize)
fontsize_col
fontsize for colnames (Default: fontsize)
display_numbers
单元显示数字
number_format
格式(C printf style) of the numbers shown in cells. For example “%.2f” shows 2 decimal places and “%.1e” shows exponential notation (see more in sprintf).
number_color
文字颜色
fontsize_number
数字大小
gaps_row
加入间隙,仅在列不聚类时使用。
See cutree_row to see how to introduce gaps to clustered rows.
gaps_col
。。。。。。。。。。
labels_row
行名替换,不使用rownames。Exp:labels <-c(“1111”,”2222”)
labels_col
……..
filename
存储图片,格式 png, pdf, tiff, bmp, jpeg.
width
输出文件的宽度
height
。。。。。。。。。
silent
do not draw the plot (useful when using the gtable output)

graphical parameters for the text used in plot. Parameters passed to grid.text, seegpar.
Details

The function also allows to aggregate the rows using kmeansclustering. This is advisable if number of rows is so big that R cannot handletheir hierarchical clustering anymore, roughly more than 1000. Instead ofshowing all the rows separately one can cluster the rows in advance and showonly the cluster centers. The number of clusters can be tuned with parameterkmeans_k.
Value

Invisibly a list of components
·
tree_row the clustering of rowsas hclust object
·
·
tree_col the clustering of columnsas hclust object
·
·
kmeans the kmeans clustering ofrows if parameter kmeans_k was specified
·

  • 3
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值