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?
Asked
Active
Viewed 34 times
0
-
1Welcome to SO! It would be easier to help you if you provide [a minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) including the code you tried and a snippet of your data or some fake data. While the general answer to your question is probably "yes" it lacks the necessary details and clarity to give a definitive answer. – stefan Apr 04 '22 at 20:10
1 Answers
2
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)

Allan Cameron
- 147,086
- 7
- 49
- 87