R语言学习笔记:Pheatmap包

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, "*", ""))
#添加列注释信息1+将导入的注释信息转化为data.frame格式
annotation_col <- read.csv2("Peter_col.csv",header=T,row.names = 1)
annotation_col <- as.data.frame(annotation_col) 
#添加行注释信息1+将导入的注释信息转化为data.frame格式
annotation_row <- read.csv2("Peter_row.csv",header=T,row.names = 1)
annotation_row <- as.data.frame(annotation_row) 
#添加列注释信息2
annotation_col = data.frame(
  Peter1= c(rep("NO",1),rep("YES",1)),
  Peter2 = c(rep("NO",1),rep("YES",1)),
  Type = c(rep("Type1",1),rep("Type2",1)
)
row.names(annotation_col) <- colnames(Peter)
#添加行注释信息2
annotation_row = data.frame(Pathway = c(rep("Pathway1",1),rep("Pathway2",1))
row.names(annotation_row) <- rownames(Peter)
#查看行注释内容
View(annotation_row)
#查看行注释内容
View(annotation_col)
#定义注释内容颜色
ann_colors = list(
  Peter1 = c(NO = "#FFFFFF", YES = "#000000"),
  Peter2 = c(NO = "#FFFFFF", YES = "#000000"),
  Type = c(Type1 = "#FFAEB9", Type2 = "#FF7F00")
)
#pheatmap的各种参数
pheatmap(
  Peter, 
  show_colnames=F, 
  cluster_cols = FALSE, cluster_rows = FALSE,
  cellwidth = 6.5, cellheight = 6.5, fontsize = 4.5,
  gaps_row = c(1,3,5),
  gaps_col = c(1,3,5),
  row_split = annotation_row$Pathway,#按行分类截断
  column_split = annotation_col$Peter1,#按列分类截断
  annotation_col = annotation_col, annotation_row = annotation_row, 
  annotation_colors = ann_colors, annotation_legend = FALSE
)

  • 11
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值