I've been trying to export a ggplot2 plot to PDF. The problem is that I've been adding exotic font to my plots, and -as a consequence- the exported PDF don't show any text.
I made sure to import my font as such:
library(extrafont)
font_import(pattern = 'Arch')
loadfonts()
and I export to a PDF after my ggplot2 plot is put in a variable "p
" :
ggsave("myPlot.pdf", plot=p, width=4, height=6)
embed_fonts("myPlot.pdf", outfile="myPlot_embed.pdf")
I then get an error saying:
GhostScript was not found
This page, however, seems to suggest no other steps should be needed on Mac OS (there's an extra step on Windows): https://github.com/wch/extrafont
Any idea on what am I doing wrong?
The instruction guidelines for the extrafont package you quoted (https://github.com/wch/extrafont/blob/master/README.md) clearly state:
"You must have Ghostscript installed on your system for embedding fonts into PDF files."
So as a start, please check if you have Ghostscript installed at all:
If yes, make sure it is in the $PATH
, or that its installation location is included in the $PATH
variable.
If no, install Ghostscript first. You can use the method described below.
First, install the MacPorts framework. MacPorts provides a package management system and ready-made packages which allow you to install a log of GNU and other Free Software packages.
Installation instructions are different, depending on your version of OS X:
After you have MacPorts, run this command in a Terminal.app window:
sudo port selfupdate
MacPorts has a Ghostscript package. You can install it like this, via commands in a Terminal.app window:
sudo port install ghostscript
This command will draw in and install more packages which are required by Ghostscript as "dependencies".
Please note:
After this installation, you'll have a Ghostscript executable placed as /opt/local/bin/gs
. (There will be even more helper programs in /opt/local/bin/
.)
This requires that you need to put that directory into your $PATH
. Therefore, put this line into your ~/.bashrc
:
export PATH=/opt/local/bin:$PATH
There are other options which you could try to install Ghostscript. One is HomeBrew -- but I have no personal experience with this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With