library(pheatmap)
#导入方式1:读取剪切板中的内容
Peter <- read.table(pipe("pbpaste"))
#导入方式2:读取文件内容
Peter <- read.table("Peter.csv",header=T, sep=",",row.names = 1)
#做热图所需内容格式需要为矩阵,矩阵化
Peter <- as.matrix(Peter)
#获取向量/矩阵/表/数据框/函数的一部分
head(Peter)
#默认绘图
pheatmap(Peter)
#自定义热图颜色+热块边框线有无
pheatmap(Peter, color = colorRampPalette(c("navy", "white", "firebrick3"))(100),
border = FALSE)
#设定边框线色
pheatmap(Peter, border_color = "blue")
#不绘制渐变图的图例
pheatmap(Peter, legend = FALSE)
#热图块内显示数值
pheatmap(Peter, display_numbers = TRUE)
#设定数值字符串的格式及颜色
pheatmap(Peter, display_numbers = TRUE, number_format = "%.1e",number_color = "blue")
#构建矩阵文本,填充热图块
pheatmap(Peter, display_numbers = matrix(ifelse(Peter > 5, "*", ""), nrow(Peter)))
#等同
pheatmap(Peter, display_numbers = ifelse(test > 5, "*"
R语言学习笔记:Pheatmap包
于 2023-12-08 22:59:05 首次发布