Saving `ggplot2` plots as PDFs without embedding fonts in RStudio

Hi folks,

Just a quick one - is there any way to save a ggplot2 object in R without embedding the fonts? I'm not even sure if I'm using the correct vocabularly for this, but by default using ggsave() the fonts remain highlightable.

image

I want to do what Inkscape refers to as "converting text to paths" - turning text into static vector images.

image

Usually to achieve this I save a plot as an SVG and then use the Inkscape menu above to convert the SVG into a PDF with converted text. Is there a way to do this programatically from RStudio? I tried saving an an SVG then converting to a PDF using rsvg::rsvg_pdf(), but that leaves the text alone.

In the right above pane, thereĀ“s plots, click in export tab and keep it in pdf.

I just know remove y or x names, I hope it helps:

your ggplot code +
theme_avoid()

or:

your ggplot code +
theme(axis.title.x = element_blank(),
axis.text.y = element_blank())

Hi @bustosmiguel,

That's not quite what I'm after. When you save as PDF through RStudio or ggsave() the text isn't coverted to "paths".

Thank you for your answer about theme(), but I don't want to get rid of the text. I want to retain the text, but have it not be embedded as text but instead coverted to a vector image.

Okay I've been able to do it via svg(), though I am open to other suggestions.

ggpdf = function(filename, plot, height, width, keep_svg = FALSE, ...){

  filename = gsub(filename,
                  pattern = "\\.svg|\\.pdf",
                  replacement = "")

  svgname = paste0(filename, ".svg")
  pdfname = paste0(filename, ".pdf")

  svg(filename = svgname, width = width, height = height, ...)
  plot(plot)
  dev.off()

  rsvg::rsvg_pdf(svg = svgname, file = pdfname)

  if(!keep_svg){unlink(svgname)}

}

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.