Hi, I hope this works. This is the first time I have tried posting a reprex.
table_pval <- tibble::tribble(
~Model, ~Predictor, ~Mono, ~Neu, ~NK, ~CD4T, ~CD8T, ~Bcell,
"Model 1", "Case-Control", 0.628417355082566, 0.000519604887456513, 0.0925500673787777, 0.00584722383176443, 0.00110636778126264, 0.00448981271134747,
"Model 2a", "Case-Control", 0.776347680248465, 0.00333944782506215, 0.286264314573566, 0.0186336833741003, 0.00974265172264351, 0.0260571208261442,
"Model 2b", "Hour diff SCZ", 0.0684626664059519, 0.531113835122065, 0.232291839314412, 0.661674211090156, 0.303802763736016, 0.33771624522132,
"Model 3", "Hour diff CTL", 0.00692340728223628, 0.851856936368742, 0.25075981812509, 0.945866144505559, 0.348892587472004, 0.680282551421654
)
head(table_pval)
library(magrittr)
library(gt)
## function for writing stars of significance (https://github.com/rstudio/gt/issues/187)
fmt_stars <- function(tble.pval,
columns,
rows = NULL) {
rows <- rlang::enquo(rows)
fmt(
data = tble.pval,
columns = columns,
rows = !!rows,
fns = list(
default = function(x) {
x_str <-
dplyr::case_when(
between(x, 0, 0.001) ~ "***",
between(x, 0, 0.01) ~ "**",
between(x, 0, 0.05) ~ "*",
TRUE ~ "."
)
}
)
)
}
## table of pvalues that doesn´t show stars of significance
tbl.pval <- gt(table_pval) %>%
fmt_stars(columns = 3:8) %>%
fmt_number(
columns = 3:8,
decimals = 3) %>%
tab_header(
title = "SCZ status and Time-of-blood draw",
subtitle = "Impact on estimated cell-type proportions"
)
tbl.pval
## get an error that data is not gt_table format when trying to add a footnote
tble.pval <- gt(table_pval) %>%
fmt_stars(columns = 3:8)%>%
fmt_number(
columns = 3:8,
decimals = 3) %>%
tab_header(
title = "SCZ status and Time-of-blood draw",
subtitle = "Impact on estimated cell-type proportions"
) %>%
tab_footnote(
footnote = md("Represents **hours from baseline 07:00**."),
locations = cells_body(
columns = 2, rows = starts_with("Hour")
) %>%
opt_footnote_marks(marks = "+"))
tble.pval