Skip to contents

A theme element that renders text labels as markdown. Use in place of ggplot2::element_text() for plot titles, subtitles, captions, axis labels, etc.

Usage

element_md(
  family = NULL,
  code_font_family = NA_character_,
  face = NULL,
  colour = NULL,
  size = NULL,
  hjust = NULL,
  vjust = NULL,
  angle = NULL,
  lineheight = NULL,
  color = NULL,
  margin = NULL,
  debug = FALSE,
  inherit.blank = FALSE,
  width = NA_real_
)

Arguments

family

Font family.

code_font_family

Font family for inline code. NA, the default, takes the font of the theme element it inherits from, else "mono".

face

Font face ("plain", "bold", "italic", "bold.italic").

colour, color

Text color.

size

Font size in points.

hjust

Horizontal justification (0-1).

vjust

Vertical justification (0-1).

angle

Text rotation angle in degrees.

lineheight

Line height multiplier.

margin

Margins around the text (use ggplot2::margin()).

debug

Show debug rectangles.

inherit.blank

Should this element inherit blank elements.

width

Maximum width of the text in inches, for titles, subtitles and captions, which wrap to their available width by default. With 'patchwork' or a fixed aspect ratio, the available width is not known when the height of the title is computed: the text may need more lines than the space kept for it, and setting width solves this. It is ignored for rotated text and for text with an explicit position. NA, the default, sets no width.

Value

An S7 element of class element_md, which extends ggplot2::element_text().

Examples

library(ggplot2)

library(gdtools)
font_set_liberation()
#> Font set
#>   sans:    Liberation Sans [liberation]
#>   serif:   Liberation Serif [liberation]
#>   mono:    Liberation Mono [liberation]
#>   symbol:  Liberation Sans [liberation]
#>   4 HTML dependencies
flextable::set_flextable_defaults(
  font.size = 12,
  font.family = "Liberation Sans"
)

p1 <- ggplot(mtcars, aes(mpg, wt)) +
  geom_point() +
  labs(title = "**Bold title** with *italic*") +
  theme(plot.title = element_md())

girafe(
  ggobj = p1,
  dependencies = list(
    liberationsansHtmlDependency()
  )
)
p2 <- ggplot(mtcars, aes(mpg, wt)) + geom_point() + labs( title = "**MPG** vs *Weight*", caption = "Source: `mtcars` dataset" ) + theme( plot.title = element_md(size = 16), plot.caption = element_md(size = 9) ) girafe( ggobj = p2, check_fonts_dependencies = TRUE )