wilkelab / ggtext

Improved text rendering support for ggplot2
https://wilkelab.org/ggtext/
GNU General Public License v2.0
655 stars 37 forks source link

Markdown axis text not showing up with save_plot() #6

Closed mmjohn closed 4 years ago

mmjohn commented 4 years ago

I'm running into an issue when I try to save a plot that has markdown elements in the y axis title. I added a lambda symbol to the y axis using ggtext. There's no issue displaying it within RStudio, but when I save the plot with save_plot(), the lambda in the y axis is converted to two dots.

library(tidyverse)
library(cowplot)
library(ggtext)

ggplot(iris) +
  geom_point(aes(x = Sepal.Length, y = Sepal.Width)) +
  labs(x = "*n*<sub>eff</sub>", y = "&lambda;<sup>-1</sup>") +
  theme(axis.title.x = element_markdown(),
        axis.title.y = element_markdown()) -> plot1

plot1 

save_plot("plot1.pdf", plot1, ncol = 1, nrow = 1, base_height = 5,
          base_asp = 1.618, base_width = NULL)
clauswilke commented 4 years ago

Unfortunately not all R graphics devices support the same feature set. In general, if something works in one graphics device (here, the RStudio viewer) but not in another (here, pdf()), then it's the graphics device's fault. Saving as png instead of pdf may help.