A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://davidgohel.github.io/flextable/reference/gen_grob.html below:

Convert a flextable to a grid grob object — gen_grob • flextable

It uses Grid Graphics (package grid) to Convert a flextable into a grob object with scaling and text wrapping capabilities.

This method can be used to insert a flextable inside a ggplot2 plot, it can also be used with package 'patchwork' or 'cowplot' to combine ggplots and flextables into the same graphic.

User can vary the size of the elements according to the size of the graphic window. The text behavior is controllable, user can decide to make the paragraphs (texts and images) distribute themselves correctly in the available space of the cell. It is possible to define resizing options, for example by using only the width, or by distributing the content so that it occupies the whole graphic space. It is also possible to freeze or not the size of the columns.

It is not recommended to use this function for large tables because the calculations can be long.

Limitations: equations (see as_equation()) and hyperlinks (see officer::hyperlink_ftext()) will not be displayed.

'ragg' or 'svglite' or 'ggiraph' graphical device drivers should be used to ensure a correct rendering.

Usage
gen_grob(
  x,
  ...,
  fit = c("auto", "width", "fixed"),
  scaling = c("min", "full", "fixed"),
  wrapping = TRUE,
  autowidths = TRUE,
  just = NULL
)
Arguments
x

A flextable object

...

Reserved for extra arguments

fit

Determines the fitting/scaling of the grob on its parent viewport. One of auto, width, fixed, TRUE, FALSE:

scaling

Determines the scaling of the table contents. One of min, full, fixed, TRUE, FALSE:

wrapping

Determines the soft wrapping (line breaking) method for the table cell contents. One of TRUE, FALSE:

Superscript and subscript chunks do not wrap. Newline and tab characters are removed from these chunk types.

autowidths

If TRUE (default) the column widths are adjusted in order to fit the contents of the cells (taking into account the wrapping setting).

just

Justification of viewport layout, same as just argument in grid::grid.layout(). When set to NULL (default), it is determined according to the fit argument.

Value

a grob (gTree) object made with package grid

size

The size of the flextable can be known by using the method dim on the grob.

caption

It's important to note that captions are not part of the table itself. This means when exporting a table to PNG or SVG formats (image formats), the caption won't be included. Captions are intended for document outputs like Word, HTML, or PDF, where tables are embedded within the document itself.

See also

Other flextable print function: df_printer(), flextable_to_rmd(), htmltools_value(), knit_print.flextable(), plot.flextable(), print.flextable(), save_as_docx(), save_as_html(), save_as_image(), save_as_pptx(), save_as_rtf(), to_html.flextable()

Examples
library(ragg)
library(gdtools)
register_liberationsans()
#> [1] TRUE

set_flextable_defaults(font.family = "Liberation Sans")

ft <- flextable(head(mtcars))

gr <- gen_grob(ft)

png_f_1 <- tempfile(fileext = ".png")
ragg::agg_png(
  filename = png_f_1, width = 4, height = 2,
  units = "in", res = 150)
plot(gr)
dev.off()
#> pdf 
#>   2 

png_f_2 <- tempfile(fileext = ".png")
# get the size
dims <- dim(gr)
dims
#> $width
#> [1] 8.25
#> 
#> $height
#> [1] 1.763638
#> 
ragg::agg_png(
  filename = png_f_2, width = dims$width + .1,
  height = dims$height + .1, units = "in", res = 150
)
plot(gr)
dev.off()
#> pdf 
#>   2 


if (require("ggplot2")) {
  png_f_3 <- tempfile(fileext = ".png")
  z <- summarizor(iris, by = "Species")
  ft <- as_flextable(z, spread_first_col = TRUE)
  ft <- color(ft, color = "gray", part = "all")
  gg <- ggplot(data = iris, aes(Sepal.Length, Petal.Width)) +
    annotation_custom(
      gen_grob(ft, scaling = "full"),
      xmin  = 4.5, xmax = 7.5, ymin = 0.25, ymax = 2.25) +
    geom_point() +
    theme_minimal()
  ragg::agg_png(
    filename = png_f_3, width = 7,
    height = 7, units = "in", res = 150
  )
  print(gg)
  dev.off()
}
#> Loading required package: ggplot2
#> pdf 
#>   2 



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4