title: ggplot2 ggsave: keep embedded fonts in exported .png
body: <p>Numerous people have had the issue where a custom font shows up in the ggplot but disappears upon export using <code>ggsave</code>, but I've only ever found solutions to this for exporting pdfs (e.g. <a href="https://stackoverflow.com/questions/27542302/ggplot-embedded-fonts-in-pdf">ggplot embedded fonts in pdf</a>). I'm trying to export as png. This has previously worked fine for me, so not sure what's going on. </p>
  
  <p>Just updated everything, which didn't fix the issue - R is version 3.5.0; RStudio is 1.1.453; on macOS Sierra.</p>
  
  <p>Both of these work to add the font to the plot:</p>
  
  <p>1:</p>
  
  <pre><code>if (!require(showtext)) {
    install.packages("showtext", repos = "http://cran.utstat.utoronto.ca/")
    require(showtext)
  }
  font_add_google("Karla", "karla") # Add nice google font
  showtext_auto() # Tell R to use showtext to render google font
  </code></pre>
  
  <p>2:</p>
  
  <pre><code>if (!require(extrafont)) {
    install.packages("extrafont", repos = "http://cran.utstat.utoronto.ca/")
    require(extrafont)
  }
  font_import(pattern = "Karla")
  </code></pre>
  
  <p><strong>How I'm plotting it:</strong></p>
  
  <pre><code>theme_map &lt;- function(...) {
    theme_minimal() +
      theme(
        text = element_text(family = "Karla", color = "#22211d"),
        panel.grid.minor = element_blank(),
        panel.grid.major = element_blank(),
        plot.background = element_rect(fill = "#f5f5f2", color = NA), 
        panel.background = element_rect(fill = "#f5f5f2", color = NA), 
        legend.background = element_rect(fill = "#f5f5f2", color = NA),
        panel.border = element_blank(), # infuriatingly doesn't work but that's unrelated
        aspect.ratio = 9 / 16, # 16:9 aspect ratio
        ...
      )
  }
  
  data(iris)
  
  p &lt;- ggplot() + geom_point(data=iris, aes(x=iris$Sepal.Length, y=iris$Sepal.Width)) + labs(title="Font Pls") + theme_map()
  
  plot(p)
  
  ggsave("iris.png", p, device="png")
  ggsave("iris.png", p, device="png", type="cairo") # does not produce an error but also doesn't produce a .png file
  ggsave("iris.png", p, device="cairo-png") # also does not produce an error but also doesn't produce a .png file
  </code></pre>
  
  <p><strong>What I see in RStudio</strong> (and want to save):
  <a href="https://i.stack.imgur.com/eHB2g.png" rel="noreferrer"><img src="https://i.stack.imgur.com/eHB2g.png" alt="RStudio plot with Karla! :)"></a></p>
  
  <p><strong>What gets saved using ggsave:</strong>
  This is what is spit out using <code>ggsave</code>, even with solutions provided elsewhere like <code>type = "cairo-png"</code> or <code>type = "cairo"</code>. (Adding either of those just gives an error, doesn't save the plot at all.) Not sure if it's related (though it probably is), but ggsave also appears to be ignoring the text sizes and italics for the title, axes, etc. </p>
  
  <p><a href="https://i.stack.imgur.com/kjuzG.png" rel="noreferrer"><img src="https://i.stack.imgur.com/kjuzG.png" alt="ggsave without Karla font &gt;:("></a></p>
  
  <p>I'm happy to use a non-ggsave solution if it's out there. I have hundreds of images I need to export in this format so "export it as a pdf then save as a png" is not an option.</p>