Skip to contents

Transform any ggplot2 theme into a theme that renders text as markdown

Usage

theme_as_md(theme, all_plain = TRUE)

Arguments

theme

An object of class ggplot2::theme

all_plain

logical (default = TRUE). Should all text be plain by default?

Examples

library(ggplot2)
data(mtcars)

# Create a custom theme
my_theme <- theme_gray() +
  theme(
    panel.grid.minor = element_blank(),
    panel.grid.major = element_blank()
  )
p <- ggplot(mtcars, aes(hp)) +
  geom_histogram() +
  ggtitle("Mixing **bold** and *italics* is easy")

# Text is not rendered
p + my_theme
#> `stat_bin()` using `bins = 30`. Pick better value `binwidth`.


# Text is rendered properly
p + theme_as_md(my_theme)
#> `stat_bin()` using `bins = 30`. Pick better value `binwidth`.