wrap_labs: Format title, subtitle, and caption of a ggplot2 chart in the...

View source: R/wrap_labs.R

wrap_labsR Documentation

Format title, subtitle, and caption of a ggplot2 chart in the Grattan style.

Description

Use 'wrap_labs()' to wrap the title, subtitle, and caption of a ggplot2 chart onto multiple lines, left-align them, and split 'notes' and 'source' onto multiple lines. Note that this is done automatically for you if you use 'grattan_save()' - there is no need to use 'wrap_labs()' if you also plan to use 'grattan_save()'.

Usage

wrap_labs(
  object,
  type,
  labs_to_wrap = c("title", "subtitle", "caption"),
  ignore_long_title = TRUE
)

Arguments

object

Name of the ggplot2 chart object with the labels you wish to modify.

type

The type of chart you intend to save (different chart types have different numbers of characters on each line). ‘type' can be ’normal', 'fullslide', 'blog', etc. For a full list of possible types, see ?grattan_save().

labs_to_wrap

Default is c("title", "subtitle", "caption"), which wraps all three labels. Choose one or two if you only want to wrap those.

ignore_long_title

Default is FALSE. If TRUE, the check on a long title won't be performed. This is useful if using ggtext syntax within titles.

Examples


library(ggplot2)
p <- ggplot(mtcars, aes(x = wt, y = mpg)) +
    geom_point() +
    theme_grattan() +
    labs(title = "My title goes here and is quite long and needs to break
    over two lines, as is common for Grattan charts",
    subtitle = "Subtitle goes here",
    caption = "Notes: Put some notes here. Source: Put your source here.")

p_wrapped <- wrap_labs(p, "normal")

p_wrapped


MattCowgill/grattantheme documentation built on Jan. 13, 2023, 11:02 a.m.