Learn R Programming

munch (version 0.0.3)

element_md: Markdown Theme Element for ggplot2

Description

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 = NULL,
  face = NULL,
  colour = NULL,
  size = NULL,
  hjust = NULL,
  vjust = NULL,
  angle = NULL,
  lineheight = NULL,
  color = NULL,
  margin = NULL,
  debug = FALSE,
  inherit.blank = FALSE,
  width = NULL
)

Value

An element of class c("element_md", "element_text", "element").

Arguments

family

Font family.

code_font_family

Font family for inline code. Defaults to "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.

Examples

Run this code
if (FALSE) { # require("ggiraph", quietly = TRUE, character.only = TRUE)
library(ggplot2)

library(gdtools)
font_set_liberation()
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
)
}

Run the code above in your browser using DataLab