Issue Exporting Plots with different fonts in R using ggsave

I am trying to export plots with different font text in R using the ggplot2 package and the ggsave function. When I attempt to save the plot as an EPS file, the specified font is ignored.

I would like to know if there is a solution to this issue or if I should use another export format.

Here is the code I am using to generate and export the plot:

# Load the necessary packages
library(tidyverse)
library(palmerpenguins)
library(extrafont)

# extrafont::font_import()  # to be called just once, after installing the extrafont package (or whenever you install a new font)
extrafont::loadfonts(device = "pdf") # call this once per session
extrafont::fonts() # get a list of fonts

# Create the plot
penguin_plot <- penguins |>
  filter(!is.na(flipper_length_mm)) |>
  ggplot(aes(x = flipper_length_mm, fill = species)) +
  geom_histogram(alpha = 0.6, position = "identity", bins = 30) +
  xlab("Flipper Length (mm)") +
  ylab("Frequency") +
  ggtitle("Distribution of flipper length, by species") +
  theme(text = element_text(family = "Gill Sans MT"), title = element_text(face = "italic"))

print(penguin_plot)

# Try to save as EPS with transparency
  ggsave(
    filename = "penguin_plot.eps",
    plot = penguin_plot,
    device="eps",
    family = "Gill Sans MT"
  )

# Warning message:
#   In grid.Call.graphics(C_rect, x$x, x$y, x$width, x$height, resolveHJust(x$just,  :
#   semi-transparency is not supported on this device: reported only once per page

Thank you for your assistance!

This topic was automatically closed 90 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.