replace_plot_labels: Replace variable names with labels in ggplot

View source: R/lblCode.R

replace_plot_labelsR Documentation

Replace variable names with labels in ggplot

Description

If the data stored in a ggplot object has variable labels then this will replace the variable names with the variable labels. If no labels are set then the variable names will be tidied and a nicer version used.

Usage

replace_plot_labels(plot)

Arguments

plot

output from a call to ggplot2

See Also

set_var_labels() for setting individual variable labels, set_labels() for setting variable labels using a data frame, extract_labels() for creating a data frame of all variable labels, clear_labels() for removing variable labels

Examples

## Not run: 
data("pembrolizumab")
p <- ggplot(pembrolizumab,aes(x=change_ctdna_group,y=baseline_ctdna)) +
geom_boxplot()
replace_plot_labels(p)
pembrolizumab <- set_var_labels(pembrolizumab,
change_ctdna_group="Change in ctDNA group")
p <- ggplot(pembrolizumab,aes(x=change_ctdna_group,y=baseline_ctdna)) +
geom_boxplot()
replace_plot_labels(p)
# Can also be used with a pipe, but expression needs to be wrapped in a brace
(ggplot(pembrolizumab,aes(x=change_ctdna_group,y=baseline_ctdna)) +
geom_boxplot()) |> replace_plot_labels()

## End(Not run)

reportRmd documentation built on April 4, 2025, 2:03 a.m.