When using ggplot, we map columns to aesthetics, so we always end up with axis/legend titles from the column names. However these follow some R symbol casing like snake case or other. However in a plot it's nicer to have sentence- or title case labels.
I was trying to write a function that can take a plot and a renaming function (like stringr::str_to_title() as input and maps the latter over the ggplot labels. A bit like rename_with()
, but then labs_with()
. So in the end I'm aiming for something that can be used like this:
iris |>
ggplot(aes(Sepal.Length, Sepal.Width, fill = Species)) +
geom_point() +
labs_with(str_to_title)
This way I don't have to rename everything manually with labs()
However, I got pretty stuck with this. Anybody here any thoughts?