I can no longer use stringr::str_wrap()on text that has ggtext::element_markdown() applied to it.
library(ggplot2)
library(ggtext)
library(stringr)
# Basic Plot
ggplot(mtcars, aes(mpg, hp)) +
geom_point() +
ggtitle("The data was extracted from the 1974 Motor Trend US magazine.")
# Plot with str_wrap
ggplot(mtcars, aes(mpg, hp)) +
geom_point() +
ggtitle(str_wrap("The data was extracted from the 1974 Motor Trend US magazine.", width = 50))
# Plot with str_wrap and ggtext
ggplot(mtcars, aes(mpg, hp)) +
geom_point() +
ggtitle(str_wrap("The data was extracted from the 1974 Motor Trend US magazine.", width = 50)) +
theme(plot.title = element_markdown())
Yes, markdown absorbs newlines. You could use gsub() to replace \n with <br>, or you could use element_textbox() to let it handle the word wrapping. In my opinion, the second option makes more sense.
Hello,
I can no longer use
stringr::str_wrap()
on text that hasggtext::element_markdown()
applied to it.Created on 2020-10-19 by the reprex package (v0.3.0)