Skip to contents

Creates a grob directly from flextable chunk data.frames (created with flextable::as_paragraph()), bypassing markdown parsing.

Usage

chunks_grob(
  chunks,
  x = 0.5,
  y = 0.5,
  hjust = 0.5,
  vjust = 0.5,
  width = NULL,
  line_spacing = 1.2,
  img_baseline_ratio = 0.15,
  name = NULL
)

Arguments

chunks

A chunk data.frame from flextable (e.g., from flextable::as_paragraph()).

x

X position (0-1 in npc units).

y

Y position (0-1 in npc units).

hjust

Horizontal justification.

vjust

Vertical justification.

width

Maximum width in inches (NULL for no wrapping).

line_spacing

Line height multiplier.

img_baseline_ratio

Controls vertical alignment of inline images. Specifies the proportion of the image height below the text baseline: 0 = bottom at baseline, 0.15 = default, 0.35 = centered on text, 0.5 = centered on baseline.

name

Grob name.

Value

A grob of class "mdGrob".

Examples

#
library(grid)
library(flextable)
library(ggiraph)

library(gdtools)
#> 
#> Attaching package: ‘gdtools’
#> The following object is masked from ‘package:ggiraph’:
#> 
#>     match_family
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"
)

chunks <- as_paragraph(
  as_chunk("E = mc"),
  as_sup("2")
)
gr <- chunks_grob(chunks)

x <- girafe(
  width_svg = 1,
  height_svg = 1,
  bg = "wheat",
  options = list(opts_sizing(rescale = FALSE)),
  code = {
    grid.newpage()
    grid.draw(gr)
  },
  dependencies = list(
    liberationsansHtmlDependency()
  )
)

x
init_flextable_defaults()