[R] 保存pheatmap图片对象到文件
2024-10-19 20:28:31
一般我们使用pheatmap通过Rstudio交互得到的图片在plots的Export导出即可,如何保存对象到文件呢?这个需求在自动化流程中很常见,作者似乎也没说明。
生成示例数据:
test = matrix(rnorm(200), 20, 10)
test[1:10, seq(1, 10, 2)] = test[1:10, seq(1, 10, 2)] + 3
test[11:20, seq(2, 10, 2)] = test[11:20, seq(2, 10, 2)] + 2
test[15:20, seq(2, 10, 2)] = test[15:20, seq(2, 10, 2)] + 4
colnames(test) = paste("Test", 1:10, sep = "")
rownames(test) = paste("Gene", 1:20, sep = "")
看下数据亚子:
实现方法
接下来实现方法,分为两步:
1.保存对象
library(pheatmap)
xx <- pheatmap(test)
2. 打开图形设备重新画
这个包使用的是grid图形系统而非ggplot2,所以解决方法也是不同的。通过自定义函数来生成,也可一次绘制多个对象的图形。
save_pheatmap_pdf <- function(x, filename, width=7, height=7) {
stopifnot(!missing(x))
stopifnot(!missing(filename))
pdf(filename, width=width, height=height)
grid::grid.newpage()
grid::grid.draw(x$gtable)
dev.off()
}
save_pheatmap_pdf(xx, "test.pdf")
最新文章
- DevExpress ChartControl 样式设置
- Safari浏览器中对js Date对象的支持
- 安装python 的 包 paramiko
- Redis简单使用方法说明
- instanceof 含义
- C语言位运算
- iOS-BLE蓝牙开发持续更新
- n!的近似值 (stirling approximation)与 大O记法(big -O- notation)
- svn和ftp的区别
- hdu1005 Number Sequence(寻找循环节)
- 数据结构学习(shell排序和归并排序)
- python数据结构与算法篇:排序
- RPC是什么
- Oracle的 listagg() WITHIN GROUP ()函数使用
- 【Java每日一题】20161205
- Flash10下复制到剪切板的一种新方法
- ip字符串,二进制转十进制输出
- 4月18 数据库的CRUD操作
- TessorFlow学习 之 神经网络的构建
- JDK8集合类源码解析 - HashMap