if (FALSE) { # rlang::is_installed("ggplot2", version = "3.5.0")
library(ggplot2)
# A standard plot
base <- ggplot(mpg, aes(displ, hwy)) +
geom_point()
# Using key glyphs
base + aes(shape = drv) +
scale_shape_discrete(
# Same as using <<1>>, <<2>> and <<3>>,
# or ,  and 
# or ,  and 
name = "Cars with four wheel <<4>>, forward <> or reverse <> drive.",
guide = "marquee"
)
# Recolouring text
base <- base +
aes(colour = drv) +
labs(
colour = "Cars with {.4 four wheel}, {.f forward} or {.r reverse} drive."
)
base + guides(colour = "marquee")
# Adjust display of labels
st <- style(weight = "bold", italic = TRUE, background = NA)
base + guides(colour = guide_marquee(style = st))
# Using background instead of text colour by setting it to NULL
st <- style(color = "black", background = NULL)
base + guides(colour = guide_marquee(style = st))
# Customising style of each label through style sets
# Note: tag names must be universal per `vctrs::vec_as_names` and
# prefixed with `lab_`.
st <- classic_style()
st <- modify_style(st, tag = "lab_f", background = NULL, color = "black")
st <- modify_style(st, tag = "lab_r", border_size = trbl(1),
color = "black", background = NA)
base + guides(colour = guide_marquee(style = st))
# Alternatively:
base + guides(colour = "marquee") +
theme(plot.subtitle = element_marquee(style = st))
# Splicing in labels by number (!!2) or label (!!subcompact)
base + aes(colour = class) +
labs(colour = "Cars including !!2 and !!subcompact vehicles") +
guides(colour = "marquee")
# Using automatic detection
base + aes(colour = class) +
labs(colour = "Cars including suv and minivan vehicles") +
guides(colour = guide_marquee(detect = TRUE))
}
Run the code above in your browser using DataLab