View source: R/gridify-classes.R
| gridify | R Documentation |
This function creates a gridify object, which represents an object with a specific layout and text elements around the output. The object can be a grob, ggplot2, gt, flextable, formula object. The layout can be a gridifyLayout object or a function that returns a gridifyLayout object.
gridify(object = grid::nullGrob(), layout, elements = list(), ...)
object |
A grob or ggplot2, gt, flextable, formula object. Default is |
layout |
A gridifyLayout object or a function that returns a gridifyLayout object.
You can use predefined layouts; the |
elements |
A list of text elements to fill the cells in the layout.
Useful only in specific situations, please consider using |
... |
Additional arguments. |
The elements argument is a list of elements to fill the cells, it can be used
instead of or in conjunction with set_cell.
Please access the vignettes for more information about gridify.
A gridifyClass object.
When setting your text within the elements argument, you can add new lines by using the newline character, \n.
The addition of \n may require setting a smaller lineheight argument in the grid::gpar.
For all layouts with the default scales = "fixed", the layout will automatically adjust to fit the new lines,
ensuring no elements overlap.
set_cell(), show_layout(), print,gridifyClass-method, show,gridifyClass-method
library(magrittr)
object <- ggplot2::ggplot(mtcars, ggplot2::aes(mpg, wt)) +
ggplot2::geom_point()
gridify(
object = object,
layout = simple_layout()
) %>%
set_cell("title", "My Title", gpar = grid::gpar(fontsize = 30)) %>%
set_cell("footer", "My Footer", gpar = grid::gpar(fontsize = 10))
gridify(
gt::gt(head(mtcars)),
layout = complex_layout(scales = "fixed")
) %>%
set_cell("header_left", "Left Header") %>%
set_cell("header_middle", "Middle Header") %>%
set_cell("header_right", "Right Header") %>%
set_cell("title", "Title") %>%
set_cell("subtitle", "Subtitle") %>%
set_cell("note", "Note") %>%
set_cell("footer_left", "Left Footer") %>%
set_cell("footer_middle", "Middle Footer") %>%
set_cell("footer_right", "Right Footer")
# We encourage usage of set_cell but you can also use the elements argument
# to set text elements around the output.
gridify(
object = ggplot2::ggplot(data = mtcars, ggplot2::aes(x = mpg, y = wt)) +
ggplot2::geom_line(),
layout = simple_layout(),
elements = list(
title = list(text = "My Title", gpar = grid::gpar(fontsize = 30)),
footer = list(text = "My Footer", gpar = grid::gpar(fontsize = 10))
)
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.