grob_matrix()
function, along with
add_aesthetic()
, add_structure()
and
alter_at()
, help with just this, attempting to make the
process as smooth and intuitive as possible.grob_matrix()
process is intended to be
pipe-friendly.There are 3 types of groups the user can alter within a grob matrix:
cells
column_names
column_headings
All matrices / data frames inputted will have cells
but they don’t have to have column_names
, and they won’t
have column_headings
until the user adds them in after
grob_matrix()
.
grob_matrix()
to his/her matrix/data
frame.view_grob()
the user can view the current state
of the grob matrix before inserting it into a grob-layout and producing
the final PDF report.add_aesthetic()
applies a specific aesthetic to the
entire group of the matrix.?add_aesthetic
.add_structure()
applies a specific structure to the
entire matrix, and not just a specific group of the matrix like adding
an aesthetic.?add_structure
.
column_widths_p
, where providing width proportions for each
of the columns is the most useful.
df %>%
grob_matrix() %>%
add_structure(
structure = "column_widths_p",
value = c(3, 1, 1)
) %>%
view_grob()
x
will be given 3
times the amount of width as y
and z
.
add_column_headings()
must be utilized after
grob_matrix()
.
df %>%
grob_matrix() %>%
add_column_headings(
headings = list("C1", "C2"),
heading_cols = list(c(1, 2), c(3))
) %>%
view_grob()
df %>%
grob_matrix() %>%
add_column_headings(
headings = list("C1", "C2"),
heading_cols = list(c(1, 2), c(3))
) %>%
add_column_headings(
headings = list("C3", "C4", "C5"),
heading_cols = list(1, 2, 3)
) %>%
view_grob()
heading_cols
is omitted, it will be filled with an
empty space.
df %>%
grob_matrix() %>%
add_column_headings(
headings = list("C1"),
heading_cols = list(c(1, 2))
) %>%
view_grob()
df %>%
grob_matrix() %>%
add_column_headings(
headings = list("C1"),
heading_cols = list(c(1, 2))
) %>%
add_aesthetic(
aesthetic = "background_color",
value = "blue",
group = "column_headings"
) %>%
add_aesthetic(
aesthetic = "text_color",
value = "white",
group = "column_headings"
) %>%
view_grob()
grob_matrix()
, the user should utilize
alter_column_names()
.
df %>%
grob_matrix() %>%
alter_column_names(
column_names = list("C1", "C2", "C3"),
column_name_cols = list(1, 2, 3)
) %>%
view_grob()
alter_at()
is the function that is truly empowers the
user to implement cell-by-cell aesthetic / structure customization.add_aesthetic()
/ add_structure()
/
alter_at()
.
.f
argument of
alter_at()
must be a quosure style lambda
~ fun(.)
.
df %>%
grob_matrix() %>%
add_aesthetic(
aesthetic = "text_color",
value = "blue",
group = "cells"
) %>%
alter_at(
~ "red",
columns = c("x", "y"),
rows = 1
) %>%
view_grob()
df %>%
grob_matrix() %>%
add_structure("column_widths_p", 1) %>%
alter_at(~ 3, columns = 1) %>%
view_grob()
df %>%
grob_matrix() %>%
add_aesthetic(
aesthetic = "text_color",
value = "blue",
group = "cells"
) %>%
alter_at(
~ "red",
x > 1
) %>%
alter_at(
~ "steelblue",
y < 4,
aesthetic = "background_color"
) %>%
view_grob()
.f
argument is meant to be very flexible, as the
user can supply a function to apply to the selected cells to output
various aesthetics based on their values.
test_function = function(x) ifelse(x > 3, "purple", "blue")
grob_matrix_with_function = df %>%
grob_matrix() %>%
add_aesthetic(
aesthetic = "text_color",
value = "white",
group = "cells"
) %>%
alter_at(
~ test_function(.),
aesthetic = "background_color"
)
grob_matrix_with_function %>% view_grob()
grob_layout()
inside a
grob_col()
.