如何删除EPS文件的设备边距

时间:2012-12-11 17:46:30

标签: r plot

我正在将一些图表导出到EPS文件中。我的代码是

setEPS()
postscript("test.eps")
par(mar=c(0,0,0,0))
plot(1:10)
dev.off()

但我发现绘图区周围有(设备)边距。如何删除它们?谢谢。

1 个答案:

答案 0 :(得分:2)

这不是保证金。请注意代码生成的EPS中没有轴,刻度线或绘图框。没有绘制这些的空间,绘图框架将完全位于EPS的边缘。

您所看到的是R添加到轴限制的额外填充,以确保绘图字符位于绘图区域内,而不是在其边缘。 IIRC这个填充是4%。

您可以分别使用x轴和y轴的xaxsyaxs绘图参数将其关闭;见?par

 ‘xaxs’ The style of axis interval calculation to be used for the
      x-axis.  Possible values are ‘"r"’, ‘"i"’, ‘"e"’, ‘"s"’,
      ‘"d"’.  The styles are generally controlled by the range of
      data or ‘xlim’, if given.
      Style ‘"r"’ (regular) first extends the data range by 4
      percent at each end and then finds an axis with pretty labels
      that fits within the extended range.
      Style ‘"i"’ (internal) just finds an axis with pretty labels
      that fits within the original data range.
      ** editted for brevity **
      (_Only ‘"r"’ and ‘"i"’ styles have been implemented in R._)

默认为"r",而是使用:

setEPS()
postscript("test.eps")
par(mar=c(0,0,0,0), xaxs = "i", yaxs = "i")
plot(1:10)
dev.off()