# Charger les packages R requis
suppressPackageStartupMessages(library(ggpubr))
suppressPackageStartupMessages(library(dplyr))
# Exemple de données provenant de tests statistiques
stat.test <- tibble::tribble(
~supp, ~group1, ~group2, ~p.adj, ~p.signif,
"VC", "0.5", "1", 3.4e-06, "****",
"VC", "0.5", "2", 2.8e-07, "****",
"VC", "1", "2", 0.00026, "****",
"OJ", "0.5", "1", 0.00026, "****",
"OJ", "0.5", "2", 5.3e-06, "****",
"OJ", "1", "2", 0.039, "*"
)
# Créer un ggtextable
ggtab <- ggtexttable(stat.test, rows = NULL, theme = ttheme("classic"))
# Préciser les couleurs pour les p-values significatives
stat.test <- stat.test %>%
mutate(
fill = ifelse(p.adj < 0.01, "green", "gray"),
color = "black"
)
stat.test
## # A tibble: 6 x 7
## supp group1 group2 p.adj p.signif fill color
## <chr> <chr> <chr> <dbl> <chr> <chr> <chr>
## 1 VC 0.5 1 0.0000034 **** green black
## 2 VC 0.5 2 0.00000028 **** green black
## 3 VC 1 2 0.000260 **** green black
## 4 OJ 0.5 1 0.000260 **** green black
## 5 OJ 0.5 2 0.0000053 **** green black
## 6 OJ 1 2 0.039 * gray black
# Colorer le tableau de manière conditionnelle en utilisant `ggpubr::table_cell_bg()`
for(i in 1:nrow(stat.test)){
row = i+1
column = which(colnames(stat.test) == "p.adj")
ggtab <- table_cell_bg(
ggtab, row = row, column = column,
fill = stat.test$fill[i], color = stat.test$color[i]
)
}
print( ggtab)
# Pour en savoir plus : https://rpkgs.datanovia.com/ggpubr/reference/ggtexttable.html
Version: English
No Comments