2017-05-04 14 views
2

我在R中製作了一個美麗的情節用於科學期刊。根據期刊的規格,我需要一個嵌入字體的eps文件格式。由於R不會導出帶有嵌入字體的eps文件,因此我正在使用基本圖形調用embedFonts()對其進行轉換。但是,這個調用正在改變我的身材的邊界框。在下面這個簡單的例子中,白色空間被裁剪。在我的經OCD調整後的出版質量情節中,由於我已經將它完美地調整到了邊緣,所以增加了空格。embedFonts正在改變我R圖的邊界框

我想嵌入字體,但其他所有東西都保持不變!

下面是一個例子:

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需求的完整路徑,沒有蒂爾達的允許
- 指定的格式「eps2write」,因爲默認的「ps2write」將其改爲後記

我花費了很多努力在「可重複研究」上使用開放數據,開放代碼,開放期刊,bla bla bla ...我真的不想讓我的最終數字使用插圖轉換或什麼:(

+1

也許這R郵件列表線程可以幫助:http://r.789695.n4.nabble.com/eps-file-with-embedded-font-td903387.html – neilfws

回答

0

發生這種情況的原因是因爲embedFonts內部調用Ghostscript,然後嘗試行動通過修剪一些周圍的白色空間來裝配一個「最佳」邊界框來實現智能。

我們可以防止周圍繪製我們5inx3in在R.畫圖區的周邊的無形的盒子多了一個行只需添加到您的代碼段:

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") 

另一種方式去了解這是喬納森的回答這裏基本上使用sed從輸入文件中讀取邊界框信息並將其寫入輸出文件:http://r.789695.n4.nabble.com/eps-file-with-embedded-font-td903387.html正如@neilfws在上面的註釋中指出的那樣。

+0

謝謝!我將使用'box(which =「outer」,col = adjustcolor(col =「white」,alpha.f = 0)',然後這個盒子就像背景一樣透明! – rrr