Add markdown/html rich text to ggplot2 using ggtext

Install ggtext


Example to style title with both markdown and html

  • Add bold and italic to different words in title.
  • Add different colors to different words
  • Add image to title

ggplot(mtcars) + geom_boxplot(aes(as.factor(vs), mpg, fill = as.factor(am))) +
    labs(title = "**mtcars**
<img src='' width='50'></img>
: *mpg* _by_
<i style='color:blue'>vs</i> and
<strong style='color:red'>am</strong>") +
    theme(plot.title = element_markdown())
## Warning in e1[n] <- e2[n]: number of items to replace is not a multiple of
## replacement length

plot of chunk ggtext_title

More examples in ggtext