Image tools

The {govukhugo} R package includes the render_svg() function to provide improved accessibility of ggplot charts. A fuller description of this function is provided in the main documentation. This function expects that the {svglite} package is also installed.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
render_svg <- function(
  plot,
  width,
  height,
  units = "px",
  alt_title = NULL,
  alt_desc = NULL,
  caption = NULL,
  dpi = 96
)

Arguments

plot
A ggplot2::ggplot() object.
width
The desired width of the object.
height
The desired height of the object.
units
The units of width and height, the default is pixels ("px").
alt_title
Short alt text (will show as a tool-tip)
alt_desc
Longer alt text (for assistive technology)
caption
A caption to display to all users, can also be set to "alt_title" or "alt_desc" to reuse those values.
dpi
Dots per inch, default for 96 for screen resolution, switch to 300 if using physical units (e.g. mm, cm or inches).

render_svg()

The render_svg() function uses svglite to render the ggplot object, it will then insert into the plot the supplied alt text and if specified will also provide a caption for the figure.