Skip to contents

Start with a simple chart and inspect the current device. Positioned glyphs are needed for ggforma’s shaped text. A device-reported capability can still depend on the external reader that opens the finished file. Review the actual export.

library(ggplot2)
library(ggforma)
p <- ggplot(mtcars, aes(wt, mpg)) + geom_point() +
  labs(title = "Fuel economy and $hat(beta)$") +
  theme_forma() + theme(plot.title = element_markup(format = "mixed"))
forma_device_info()
   device number active positioned_glyphs
1 agg_png      2   TRUE              TRUE
                                                                                   advice
1 The device reports positioned glyph support. Use font_check() to inspect font coverage.
head(font_check("Fuel economy", "sans")[c("path", "index", "fallback", "missing")])
                           path index fallback missing
1 C:\\WINDOWS\\Fonts\\arial.ttf     0    FALSE   FALSE
2 C:\\WINDOWS\\Fonts\\arial.ttf     0    FALSE   FALSE
3 C:\\WINDOWS\\Fonts\\arial.ttf     0    FALSE   FALSE
4 C:\\WINDOWS\\Fonts\\arial.ttf     0    FALSE   FALSE
5 C:\\WINDOWS\\Fonts\\arial.ttf     0    FALSE   FALSE
6 C:\\WINDOWS\\Fonts\\arial.ttf     0    FALSE   FALSE

Three exports

PNG is a fixed-resolution image. Cairo SVG draws this shaped title as glyph outlines. Recent svglite releases also draw positioned glyphs, while svglite 2.1.3 lacks that device capability. Cairo PDF can embed font subsets. A vector file can look correct while a text search misses some of its content. Some graphics also contain raster layers.

out <- tempdir()
ggsave(file.path(out, "fuel.png"), p, device = ragg::agg_png,
       width = 6, height = 4, units = "in", dpi = 180, bg = "white")
ggsave(file.path(out, "fuel.svg"), p, device = grDevices::svg,
       width = 6, height = 4, units = "in", bg = "white")
ggsave(file.path(out, "fuel.pdf"), p, device = grDevices::cairo_pdf,
       width = 6, height = 4, units = "in", bg = "white")
stopifnot(all(file.size(file.path(out, c("fuel.png", "fuel.svg", "fuel.pdf"))) > 0))

Windows IDEs

In RStudio draw a chart to open the Plots pane, then call forma_device_info(). On the tested Windows default backend, positioned glyphs were unavailable. Select Tools → Global Options → General → Graphics → Backend → AGG, open a new device and draw the plot again. The package leaves IDE preferences under user control. Keeping the default pane and exporting directly to ragg also works.

The tested Windows Positron R device drew the mixed sample. Viewport and export behaviour can differ across releases; inspect the actual target. Large sums, radicals, integrals and limits can use different symbol fonts on ragg and Cairo. Base pdf() produced reader-dependent errors in the Windows portability sample. Use ragg PNG for a fixed raster or Cairo PDF for the tested vector route. Only the Windows stacks have been exercised locally.