grob_matrix() function, along withadd_aesthetic(),add_structure() andalter_at(), help with just this, attempting to make theprocess as smooth and intuitive as possible.grob_matrix() process is intended to bepipe-friendly.There are 3 types of groups the user can alter within a grobmatrix:
cellscolumn_namescolumn_headingsAll matrices / data frames inputted will havecellsbut they don’t have to havecolumn_names, and they won’thavecolumn_headings until the user adds them in aftergrob_matrix().
grob_matrix() to his/her matrix/dataframe.view_grob() the user can view the current stateof the grob matrix before inserting it into a grob-layout and producingthe final PDF report.add_aesthetic() applies a specific aesthetic to theentire 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 theentire matrix, and not just a specific group of the matrix like addingan aesthetic.?add_structure.column_widths_p, where providing width proportions for eachof the columns is the most useful.x will be given 3times the amount of width asy andz.add_column_headings() must be utilized aftergrob_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 anempty 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 utilizealter_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 theuser to implement cell-by-cell aesthetic / structure customization.add_aesthetic() /add_structure() /alter_at()..f argument ofalter_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_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 theuser can supply a function to apply to the selected cells to outputvarious 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()formatted_df=apply(df,2,function(x)paste0("F", x))grob_matrix_with_new_data= formatted_df%>%grob_matrix()%>%alter_at(~test_function(.), x>1,data = df,aesthetic ="text_color",group ="cells" )grob_matrix_with_new_data%>%view_grob()grob_layout() inside agrob_col().gl=grob_layout(grob_row(grob_col(grob_matrix_with_function)),grob_row(grob_col(grob_matrix_with_new_data)) )gl%>%view_grob(height =100,width =100)