0

我想将绘图的图像保存为 png 文件;但是它切断了轴标签。所以我尝试通过设置“omi”和“mar”来留出更大的余量,但它似乎不起作用。添加更多像素也不起作用。cex.lab 的较小值会使轴可见但小得难以阅读。

可能这个错误很愚蠢,但我无法弄清楚......

png(filename = "CarTheftForeigners.png",
width = 1120, height = 646, units = "px", pointsize = 12,
bg = "white", res = NA, family = "", restoreConsole = TRUE,
type = c("windows", "cairo", "cairo-png")
)
plot(Table$Car.Theft,Table$Foreigners, 
 type="p", pch=20, col="red",
 main="Correlation of the Rate of Car Theft and Rate of Foreigners", cex.main=2, 
 xlab="Rate of Car Thefts",
 ylab="Rate of Foreigners", cex.lab=2,
 par(omi=c(1,1,1,1)+0.1))
abline(reg=lm(Foreigners ~ Car.Theft, data=Table),col="blue")
dev.off()

无论我为 omi 或 mar 添加什么值,我总是会收到错误消息:

Fehler in plot.window(...) : ungültiger 'xlim' Wert

这是德语,意味着 xlim-value 无效。

感谢您的帮助!

4

1 回答 1

1

你不能par()在里面打电话plot。尝试在par之前发出呼叫plot

这成功了:

png(filename = "CarTheftForeigners.png",
    width = 1120, height = 646, units = "px", pointsize = 12)
  par(omi=c(1,1,1,1)+0.1)
  plot(1:10, 1:10)
dev.off()

这不会:

png(filename = "CarTheftForeigners.png",
     width = 1120, height = 646, units = "px", pointsize = 12);
plot(1:10, 1:10 , type="p",  par(omi=c(1,1,1,1)+0.1))
#   Error in plot.window(...) : invalid 'xlim' value
dev.off()

但是,如果您真的想在 plot() 中使用 par 调用,您可以将值命名为omi可以防止发生不正确的位置匹配。

png(filename = "CarTheftForeigners.png",
     width = 1120, height = 646, units = "px", pointsize = 12);
   plot(1:10, 1:10 , type="p",  omi = par(omi=c(1,1,1,1)+0.1))
dev.off()
于 2013-05-06T20:00:18.887 回答