ggsave_unicode: Save a ggplot with Unicode support using showtext

View source: R/plot.R

ggsave_unicodeR Documentation

Save a ggplot with Unicode support using showtext

Description

This function is a wrapper around ggplot2::ggsave() that temporarily activates the showtext graphics engine before saving. It ensures that Unicode characters (e.g., Chinese, special symbols) are rendered correctly in the saved file, regardless of the output format (vector or raster).

Usage

ggsave_unicode(plot, filename, ...)

Arguments

plot

The ggplot object to save (should be a unicode_ggplot or any ggplot object).

filename

File name to save the plot. Extension determines the format (e.g., .png, .pdf, .svg).

...

Additional arguments passed to ggplot2::ggsave(), such as width, height, dpi, units, etc.

Details

The function calls showtext::showtext_begin() before saving and ensures showtext::showtext_end() is called afterwards, even if an error occurs. It then passes all arguments to ggplot2::ggsave().

Value

Invisibly returns the filename (as ggsave does).

See Also

scatter_plot for creating plots that display correctly, print.unicode_ggplot for automatic display support.

Examples

## Not run: 
p <- scatter_plot(...)
ggsave_unicode(p, "myplot.png", width = 6, height = 4, dpi = 300)

## End(Not run)


ncmR documentation built on April 19, 2026, 5:07 p.m.