ggplot2ggtext

Rendering `%` using element_markdown()


How can I keep the % symbol in the title?

library(ggtext)
library(ggplot2)

ggplot(mtcars, aes(cyl, mpg)) +
  geom_col() +
  ggtitle("%") +
  theme(plot.title = element_markdown())

Created on 2022-01-28 by the reprex package (v2.0.1)


Solution

  • You can just add a space before and the character will display correctly. Although there is a space, the formatting of the title will ignore this:

    ggplot(mtcars, aes(cyl, mpg)) +
      geom_col() +
      ggtitle(" %") +
      theme(plot.title = element_markdown())
    

    enter image description here