首页 > 解决方案 > 以png格式保存高分辨率绘图

问题描述

我尝试将热图保存在 png 中。

png(paste(colnames(pt2)[jj], "_heatmap.png", sep=""), width = 465, height = 225, res = 300)
heatmap.2(S5, Rowv=F,Colv=F, scale="none", trace="none", col=rg, mar=c(3.5,0,3,0),
      dendrogram = "none", key=TRUE, keysize=0.2, key.par=list(cex=0.1),
      xlab="hour of the day", ylab = "day of the week",
      density.info = "none", lmat=rbind(c(5, 4, 2), c(6, 1, 3)), 
      lhei=c(3, 4.5), lwid=c(0.1, 5, 1),
      cexRow=1, cexCol=1, margins = c(3,0))
dev.off()

但它仅适用于 res=100 最大值。我还尝试将其保存到具有 10X 高度和宽度的文件中,例如宽度 = 4650,高度 = 2250。但是我无法更改键的字体大小,它太小而且看不见。如何解决高分辨率?表明

Error in plot.new() : figure margins too large
Error in par(op) : invalid value specified for graphical parameter "pin"

标签: rheatmap

解决方案


您的图片尺寸太小,无法容纳边距。请注意,默认单位png是像素。因此,您的高度为 225 像素,分辨率为 300 dpi,提供的图像高度不到一英寸

作为一个最小的例子,这是有效的(当我们将单位指定为毫米时):

png("heatmap.png", width = 465, height = 225, units='mm', res = 300)
  plot(1:10, 1:10, mar=c(3.5,0,3,0))
dev.off()

而这(以像素为单位)会引发与您相同的错误

png("heatmap.png", width = 465, height = 225, res = 300)
  plot(1:10, 1:10, mar=c(3.5,0,3,0))
dev.off()

推荐阅读