【问题标题】:embedFonts is changing the bounding box of my R plotembedFonts 正在改变我的 R 图的边界框
【发布时间】:2017-05-04 03:28:49
【问题描述】:

我在 R 中制作了一个漂亮的情节,用于科学期刊。根据期刊的规范,我需要一个带有嵌入字体的 eps 文件格式。由于 R 不导出带有嵌入字体的 eps 文件,因此我使用基本图形调用 embedFonts() 对其进行转换。然而,这个电话正在改变我的身材的边界框。在下面这个简单的例子中,空白被裁剪了。在我的强迫症调整出版质量情节中,添加了空白,因为我已经将它完美地调整到边缘。

我希望嵌入字体,但其他一切都保持不变!

这是一个例子:

setEPS()
postscript(file = "~/Desktop/test.eps", family = "Helvetica", colormodel = "srgb", width = 5, height = 3)
plot(x = 1:10, y = 1:10, col = "red", main = "Keep everything the same but embed my fonts!")
dev.off()
embedFonts(file = "/Users/athena/Desktop/test.eps", format = "eps2write", outfile = "/Users/athena/Desktop/stupid.eps")

到目前为止,我有:
- 使用自制软件安装 ghostscript:$ brew install ghostscript
- 得知embedFonts 需要完整路径,不允许使用 tilda
- 将格式指定为“eps2write”,因为默认的“ps2write”会将其更改为 postscript

我在开放数据、开放代码、开放期刊、bla bla bla 等“可重复研究”上花费了很多精力……我真的不想使用 illustrator 转换之类的东西来制作我的最终数字 :(

【问题讨论】:

标签: r ghostscript eps


【解决方案1】:

发生这种情况的原因是因为 embedFonts 内部调用 Ghostscript,而 Ghostscript 反过来又试图通过修剪周围的一些空白空间来拟合“最佳”边界框来表现得聪明。

我们可以通过在 R 中 5inx3in 绘图区域的周边绘制一个不可见的框来防止这种情况发生。只需在您的代码 sn-p 中再添加一行:

setEPS()
postscript(file = "~/Desktop/test.eps", family = "Helvetica", colormodel = "srgb", width = 5, height = 3)
plot(x = 1:10, y = 1:10, col = "red", main = "Keep everything the same but embed my fonts!")
box(which="outer", col="white")
dev.off()
embedFonts(file = "/Users/athena/Desktop/test.eps", format = "eps2write", outfile = "/Users/athena/Desktop/stupid.eps")

解决此问题的另一种方法是 Jonathan 的回答,它基本上使用 sed 从输入文件中读取边界框信息并将其写入输出文件:@neilfws 在上面的评论中指出http://r.789695.n4.nabble.com/eps-file-with-embedded-font-td903387.html。

【讨论】:

  • 谢谢!我会用box(which = "outer", col = adjustcolor(col = "white", alpha.f = 0),然后盒子也像背景一样透明!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-11-22
  • 1970-01-01
  • 2020-08-05
相关资源
最近更新 更多