2

I am preparing a paper for submission to a journal which requires vector graphics to be submitted in EPS format, with all text within figures converted to outlines. Converting text to vector outlines helps avoid font problems in the final layout. The journal requirements are available here.

EPS figures can easily be created in R using ggplot2:

library(ggplot2)
ggsave(filename = "file.eps")

or using setEPS() and the postscript device, as explained previously here:

setEPS()
postscript("filename.eps")
plot(1:10)
dev.off()

My question is: how can you convert text within the figures into vector outlines? I have found information on how to do this in other software (e.g. Illustrator or InDesign), but I would like to know if there is a way to do it directly in R.

Community
  • 1
  • 1
Lukas Weber
  • 121
  • 7

1 Answers1

1

Install ghostscript using your distro's package manager if you're under linux or download it for windows (there's also a portable version), for mac you can probably use brew. Then invoke gs or gs.exe from within R like in this SO question.

library(ggplot2)
data(diamonds)

gs.cmd <- "gs"  # ghostscript executable
# gs.cmd <- "C:/path/to/gs.exe" # Windows

p <- qplot(x=carat, y=price, color=clarity, data=diamonds)

ggsave(p, filename="test.eps")

system(paste(gs.cmd,"-o test_outline.eps -dNoOutputFonts -sDEVICE=eps2write test.eps"))
Community
  • 1
  • 1
akraf
  • 2,965
  • 20
  • 44
  • Thanks, these commands work. However I think you had a typo: the option should be `-sDEVICE=epswrite` not `-sDEVICE=eps2write`. I also added `-dEPSCrop` to avoid cropping the image. To check whether it worked, I installed `pdffonts` (part of Xpdf), converted both EPS files to PDF using `epstopdf`, then ran `pdffonts` on the PDFs to check for embedded fonts. This actually showed that neither EPS file had any embedded fonts, so `ggsave` may have already converted fonts to outlines in the original EPS. Can anyone confirm? I searched `ggplot2` documentation but couldn't find any information. – Lukas Weber Feb 23 '16 at 16:23
  • 1
    you can use `gs -h` to list the available drivers in ghostscript. At my computer, `eps2write` exists and `epswrite` does not, but that may well be different with other ghostscript versions – akraf Feb 23 '16 at 21:23