Closed mr-september closed 2 years ago
gt
table with the same style:library(gt)
pal_option = function(n, colorchoice = "A") {
if(colorchoice == "A") {
viridis::magma(n)
} else if(colorchoice == "B") {
viridis::inferno(n)
} else if(colorchoice == "C") {
viridis::plasma(n)
} else if(colorchoice == "D") {
viridis::viridis(n)
} else {
"white"
}
}
style_matrix = function(run_matrix, order_vals = FALSE, alpha = 0.3) {
. = NULL
if(order_vals) {
new_runmat = run_matrix[do.call(order, run_matrix),, drop=FALSE ]
rownames(new_runmat) = 1:nrow(new_runmat)
display_rm = gt(new_runmat[do.call(order, new_runmat),, drop=FALSE ],
rownames_to_stub = TRUE) %>%
tab_stubhead("Run") %>%
tab_options(data_row.padding = px(10)) %>%
tab_spanner(
label = "Factors",
columns = colnames(.)
) %>% tab_header(
title = "Design"
)
} else {
display_rm = gt(run_matrix,rownames_to_stub = TRUE) %>%
tab_stubhead("Run") %>%
tab_options(data_row.padding = px(10)) %>%
tab_spanner(
label = "Factors",
columns = colnames(.)
) %>% tab_header(
title = "Design"
)
}
cols_rm = colnames(run_matrix)
for(i in seq_len(length(cols_rm))) {
if(is.numeric(run_matrix[,i])) {
display_rm = display_rm %>%
data_color(
columns = cols_rm[i],
colors = pal_option(100),
alpha = alpha,
autocolor_text = FALSE)
} else {
display_rm = display_rm %>%
data_color(
columns = cols_rm[i],
colors = pal_option(length(unique(run_matrix[,i]))),
alpha = alpha,
autocolor_text = FALSE)
}
}
display_rm
}
Thank you!
For example, with the GUI, clicking on "Generate Design" gives a matrix of runs, usually with boxes colored purple/yellow.
However, for large runs, the GUI window size crops the table, preventing a whole "screenshot".