I have a legend title spread over two lines, I would like to make only the first line bold. I have the following code:
pre_legend_title = expression(paste(bold("PRE-ELECTION HATE CRIME RATES"),
"\nAverage annual hate crimes per 100,000 residents, 2010-15"))
However, when I try adding it to my ggplot using:
labs(fill = pre_legend_title)
The title doesn't break into two lines despite using \n. Is there another way to do this?
As far as I know, expression doesn't recognize linebreak characters. However, you can use the atop function:
library(ggplot2)
pre_legend_title = expression(atop(bold("PRE-ELECTION HATE CRIME RATES"),
"Average annual hate crimes per 100,000 residents, 2010-15"))
ggplot(mtcars, aes(mpg, wt, fill=factor(cyl))) +
geom_point(shape=21) +
labs(fill = pre_legend_title)

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With