wrap caption in ggplot

you can place line breaks with \n
Here is an example of replacing ALL spaces with \n

library(tidyverse)

(color_label <- stringr::str_replace_all(string = 
"How can i wrap the text in this caption in order to avoid compression of the graph?",
pattern = " ", replacement = "\n"))

iris %>%
  group_by(Species) %>%
  mutate(avg_sepal_length = mean(Sepal.Length)) %>%
  ggplot(aes(x = Species)) +
  geom_line(aes(y = avg_sepal_length, color = color_label), group = 1)
1 Like