r - 以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"
解决方案
您的图片尺寸太小,无法容纳边距。请注意,默认单位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()
推荐阅读
- string - 搜索名称与变量中的字符串部分匹配的文件
- python - Python文件写入txt文档但在读取时擦除
- android - 任务 ':app:installRelease' react-native 执行失败
- reactjs - 找不到模块“react-dom”的声明文件
- ruby-on-rails - 当两个 Rails 引擎定义一个同名的方法时,其中一个会覆盖
- python - 下拉小部件 Python
- amazon-web-services - 为 AWS Lightsail 后端实例设置 HTTPS
- javascript - 使用 javascript 在主 div 中切换其他 div 的显示
- flutter - 在 null 上调用了方法“call”。接收方:null 尝试调用:call(navegacion_bloques)
- python - 在python中解包C结构