我想知道如何在超热软件包中使用ggsave。ggsave不起作用......
# install devtools
install.packages("devtools")
# use devtools to install superheat
devtools::install_github("rlbarter/superheat")
library(superheat)
superheat(mtcars,
# scale the matrix columns
scale = TRUE,
# change the color
heat.col.scheme = "red")
g1<-superheat(mtcars,
# scale the matrix columns
scale = TRUE,
# change the color
heat.col.scheme = "red")
ggsave(file = "heat.tiff", plot =g1, width =6, height = 4)发布于 2019-12-31 06:35:37
在运行问题中的代码之后,我尝试查看superheat返回的对象是什么。
这是一个有7个成员的列表。str(g1)的输出太长,请先检查其长度:
length(g1)
#[1] 7现在看看这些列表成员中的每个成员都有哪些内容。
g1[[1]]
#TableGrob (4 x 2) "layout": 1 grobs
# z cells name grob
#1 1 (1-1,2-2) panel gTree[panel-1.gTree.303]
g1[[2]]
#TableGrob (6 x 4) "layout": 4 grobs
# z cells name grob
#1 1 (2-2,3-3) panel gTree[panel-1.gTree.303]
#2 2 (5-5,3-3) layout gtable[layout]
#3 3 (2-2,2-2) layout gtable[layout]
#4 4 (3-3,3-3) layout gtable[layout]第二个看起来很有希望,试着保存它。(实际上我也保存了g1[[1]],它是没有轴的热图。)
请注意,经过反复试验,我决定增加绘图的宽度和高度。对于问题中的值,轴注释是不可读的。
ggplot2::ggsave(file = "heat.tiff", plot = g1[[2]],
width = 12, height = 10)

最后要注意的是,图片中的图形是一个.png文件,.tiff文件显示的是完全相同的图片。
https://stackoverflow.com/questions/59537108
复制相似问题