wrap_table | R Documentation |
This function works much like wrap_elements()
in that it turns the input
into patchwork compliant objects that can be added to a composition. However,
wrap_table()
uses the knowledge that the input is a table to provide some
very nifty layout options that makes it generally better to use than
wrap_elements()
for this type of object.
wrap_table(
table,
panel = c("body", "full", "rows", "cols"),
space = c("free", "free_x", "free_y", "fixed"),
ignore_tag = FALSE
)
table |
A gt table or an object coercible to a data frame |
panel |
what portion of the table should be aligned with the panel
region? |
space |
How should the dimension of the table influence the final
composition? |
ignore_tag |
Should tags be ignored for this patch. This is relevant when using automatic tagging of plots and the content of the patch does not qualify for a tag. |
A wrapped_table object
This functionality requires v0.11.0 or higher of the gt package
library(ggplot2)
library(gt)
p1 <- ggplot(airquality) +
geom_line(aes(x = Day, y = Temp, colour = month.name[Month])) +
labs(colour = "Month")
table <- data.frame(
Month = month.name[5:9],
"Mean temp." = tapply(airquality$Temp, airquality$Month, mean),
"Min temp." = tapply(airquality$Temp, airquality$Month, min),
"Max temp." = tapply(airquality$Temp, airquality$Month, max)
)
gt_tab <- gt(table, rowname_col = "Month")
# Default addition usees wrap_table
p1 + gt_tab
# Default places column and row headers outside panel area. Use wrap_table
# to control this
p1 + wrap_table(gt_tab, panel = "full")
# Tables generally have fixed dimensions and these can be used to control
# the size of the area they occupy
p2 <- ggplot(airquality) +
geom_boxplot(aes(y = month.name[Month], x = Temp)) +
scale_y_discrete(name = NULL, limits = month.name[9:5], guide = "none")
wrap_table(gt_tab, space = "fixed") + p2
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.