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.library(grobblR)
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.= data.frame(x = c(1, 2), y = c(3, 4), z = c(5, 6))
df
%>%
df grob_matrix() %>%
view_grob()
add_aesthetic()
applies a specific aesthetic to the entire group of the matrix.?add_aesthetic
.%>%
df grob_matrix() %>%
add_aesthetic(
aesthetic = "text_color",
value = "red",
group = "cells"
%>%
) view_grob()
%>%
df grob_matrix() %>%
add_aesthetic(
aesthetic = "text_color",
value = "red",
group = "cells"
%>%
) add_aesthetic(
aesthetic = "text_color",
value = "blue",
group = "column_names"
%>%
) view_grob()
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()
%>%
df grob_matrix() %>%
alter_column_names(
column_names = list("GROUP"),
column_name_cols = list(1:2)
%>%
) 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",
> 1
x %>%
) alter_at(
~ "steelblue",
< 4,
y 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.= function(x) ifelse(x > 3, "purple", "blue")
test_function
= df %>%
grob_matrix_with_function grob_matrix() %>%
add_aesthetic(
aesthetic = "text_color",
value = "white",
group = "cells"
%>%
) alter_at(
~ test_function(.),
aesthetic = "background_color"
)
%>% view_grob() grob_matrix_with_function
= apply(df, 2, function(x) paste0("F", x))
formatted_df
= formatted_df %>%
grob_matrix_with_new_data grob_matrix() %>%
alter_at(
~ test_function(.),
> 1,
x data = df,
aesthetic = "text_color",
group = "cells"
)
%>% view_grob() grob_matrix_with_new_data
grob_layout()
inside a grob_col()
.= grob_layout(
gl grob_row(grob_col(grob_matrix_with_function)),
grob_row(grob_col(grob_matrix_with_new_data))
)
%>% view_grob(height = 100, width = 100) gl