Learn R Programming

ragg

This package provides graphic devices for R based on the AGG library developed by the late Maxim Shemanarev. AGG provides both higher performance and higher quality than the standard raster devices provided by grDevices. For a comparison with the default devices, see the performance and quality vignettes.

Installation

The package can be installed from CRAN with install.packages('ragg') or, if the development version is desired, directly from github:

# install.packages('pak')
pak::pak('r-lib/ragg')

Use

ragg provides drop-in replacements for the png, jpeg, and tiff graphic devices provided by default from the grDevices packages and can both produce png, jpeg and tiff files. Notable features, that sets itself apart from the build-in devices, includes:

  • Faster (up to 40% faster than anti-aliased cairo device)
  • Direct access to all system fonts
  • Advanced text rendering, including support for right-to-left text, emojis, and font fallback
  • High quality anti-aliasing
  • High quality rotated text
  • Support 16-bit output
  • System independent rendering (output from Mac, Windows, and Linux should be identical)

You can use it like any other device. The main functions are agg_png(), agg_jpeg() and agg_tiff(), all of which have arguments that closely match those of the png(), jpeg() and tiff() functions, so switching over should be easy.

library(ragg)
library(ggplot2)

file <- knitr::fig_path('.png')

on_linux <- tolower(Sys.info()[['sysname']]) == 'linux'
fancy_font <- if (on_linux) 'URW Chancery L' else 'Papyrus'

agg_png(file, width = 1000, height = 500, res = 144)
ggplot(mtcars) + 
  geom_point(aes(mpg, disp, colour = hp)) + 
  labs(title = 'System fonts — Oh My! 

Copy Link

Version

Install

install.packages('ragg')

Monthly Downloads

887,019

Version

1.3.3

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Thomas Lin Pedersen

Last Published

September 11th, 2024

Functions in ragg (1.3.3)

agg_jpeg

Draw to a JPEG file
agg_capture

Draw to a buffer that can be accessed directly
agg_png

Draw to a PNG file
agg_ppm

Draw to a PPM file
agg_supertransparent

Draw to a PNG file, modifying transparency on the fly
agg_tiff

Draw to a TIFF file
ragg-package

ragg: Graphic Devices Based on AGG
reexports

Objects exported from other packages