我想将我的绘图保存为png
文件,以便在其他文档中使用它们。它们需要具有固定的字体大小和高分辨率。
情节简单,但质量低。
png('myfile.png', pointsize=10)
plot(cars)
dev.off()
此处的"res"参数不起作用。我认为它也会改变我字体的实际大小。
png('myfile.png', pointsize=10, res=1200)
plot(cars)
Fehler in plot.new() : figure margins too large
png(filename = "Rplot%03d.png",
width = 480, height = 480, units = "px", pointsize = 12,
bg = "white", res = NA, ...,
type = c("cairo", "cairo-png", "Xlib", "quartz"), antialias)
正确的方法是使用宽度和高度来获得所需的分辨率
如果你想要固定的字体大小,你可以使用cex参数作为宽度和高度的一些函数所以例如
height = width * 1.2
cex = width/300
When width = 400
Height = 480
Cex = 1.33
只需找到正确的 cex 转换参数作为宽度的函数
查看这 3 个简单的代码
width=600
cex=width/300
png('myfile1.png', pointsize=10, width=width , height=width*1.2)
plot(cars , cex.lab=cex, cex=cex)
dev.off()
width=900
cex=width/300
png('myfile2.png', pointsize=10, width=width , height=width*1.2)
plot(cars , cex.lab=cex, cex=cex)
dev.off()
width=1200
cex=width/300
png('myfile3.png', pointsize=10, width=width , height=width*1.2)
plot(cars , cex.lab=cex, cex=cex)
dev.off()
字体大小与绘图分辨率成比例保持不变