I have a geom_col() with a lot of x variables, each labeled something like ABC, DEF, etc... Is there a function that will allow me to alter the existing labels all at once so that they become ABC∆, DEF∆, etc?
CodePudding user response:
You can pass a labelling function to the labels
argument of scale_x_discrete
. This takes the default label and does whatever you like to it. Here we can use a tidyverse-style lambda function to paste
the symbol Δ to the end of each label
library(ggplot2)
df <- data.frame(x = c("ABC", "DEF", "GHI", "KLM"),
y = c(3, 5, 7, 4))
ggplot(df, aes(x, y))
geom_col()
scale_x_discrete(labels = ~ paste0(.x, "\u0394"))
Created on 2022-04-04 by the reprex package (v2.0.1)