一般我们使用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")

Ref: https://stackoverflow.com/questions/43051525/how-to-draw-pheatmap-plot-to-screen-and-also-save-to-file

最新文章

  1. DevExpress ChartControl 样式设置
  2. Safari浏览器中对js Date对象的支持
  3. 安装python 的 包 paramiko
  4. Redis简单使用方法说明
  5. instanceof 含义
  6. C语言位运算
  7. iOS-BLE蓝牙开发持续更新
  8. n!的近似值 (stirling approximation)与 大O记法(big -O- notation)
  9. svn和ftp的区别
  10. hdu1005 Number Sequence(寻找循环节)
  11. 数据结构学习(shell排序和归并排序)
  12. python数据结构与算法篇:排序
  13. RPC是什么
  14. Oracle的 listagg() WITHIN GROUP ()函数使用
  15. 【Java每日一题】20161205
  16. Flash10下复制到剪切板的一种新方法
  17. ip字符串,二进制转十进制输出
  18. 4月18 数据库的CRUD操作
  19. TessorFlow学习 之 神经网络的构建
  20. JDK8集合类源码解析 - HashMap

热门文章

  1. 什么是产品待办列表?(What is Product Backlog)
  2. Java:HashMap类小记
  3. 表单编辑时el-form的validate方法执行无效,阻塞代码运行 - Element UI踩坑记录
  4. ESD
  5. 21.6.29 test
  6. 洛谷 P6075 [JSOI2015]子集选取
  7. 算法:杨辉三角(Pascal&#39;s Triangle)
  8. Django(71)图片处理器django-imagekit
  9. 2021CCPC河南省省赛
  10. C++中gSOAP的使用