# using set_cell() without the pipe operator
object <- ggplot2::ggplot(data = mtcars, ggplot2::aes(x = mpg, y = wt)) +
ggplot2::geom_line()
g <- gridify(object = object, layout = simple_layout())
g <- set_cell(g, "title", "TITLE")
g
# using set_cell() with the pipe operator
# (to use |> version 4.1.0 of R is required, for lower versions we recommend %>% from magrittr)
library(magrittr)
gridify(object = object, layout = simple_layout()) %>%
set_cell("title", "TITLE")
# using multiple lines in set_cell()
gridify(object, layout = simple_layout()) %>%
set_cell(cell = "title", text = "THIS IS THE MAIN TITLE\nA Second Title\nSubtitle") %>%
set_cell(
cell = "footer", text = "This is a footer.\nWe can have multiple lines here as well.",
x = 0, hjust = 0
)
# using mch in set_cell()
long_footer_string <- paste0(
"This is a footer. We can have a long description here.",
"We can have another long description here.",
"We can have another long description here."
)
gridify(object, layout = simple_layout()) %>%
set_cell(
cell = "footer", long_footer_string, mch = 60, x = 0, hjust = 0
)
# using the location and alignment arguments
# the left side of the text is on the left side of the cell
gridify(object = object, layout = simple_layout()) %>%
set_cell("title", "TITLE", x = 0, hjust = 0)
# the right side of the text is on the right side of the cell
gridify(object = object, layout = simple_layout()) %>%
set_cell("title", "TITLE", x = 1, hjust = 1)
# the right side of the text is 30% from the right side of the cell
gridify(object = object, layout = simple_layout()) %>%
set_cell("title", "TITLE", x = 0.7, hjust = 1)
# using the rotation argument
gridify(object = object, layout = simple_layout()) %>%
set_cell("title", "TITLE", x = 0.7, rot = 45)
# using the graphical parameters argument
gridify(object = object, layout = simple_layout()) %>%
set_cell("title", "TITLE", x = 0.7, rot = 45, gpar = grid::gpar(fontsize = 20)) %>%
set_cell("footer", "FOOTER", x = 0.2, y = 1, gpar = grid::gpar(col = "blue"))
Run the code above in your browser using DataLab