vincentarelbundock / modelsummary

Beautiful and customizable model summaries in R.
http://modelsummary.com
Other
896 stars 74 forks source link

Add footnote to model title in Quarto #782

Closed timonscheuer closed 3 weeks ago

timonscheuer commented 3 weeks ago

Hi! I don't want to report a bug, but I have a question. I'm using modelsummary in Quarto together with kableExtra to generate a PDF.

My question is this: The model-titles are the names of the models provided in a list. I want to add a footnote to the title of one of the four models in my table (otherwise the name would be quite long). As it does not seem to be possible to omit these names and add them manually by add_header_above without creating an empty row, is it somehow possible to add footnotes (or at least a ^1) to the model titles? If I try that, the result is "Wahlteilnahme, niedrig^1" instead of a superscripted 1.

How can I change that? Or is there a different way to add footnotes to model titles?

Thank you!

names(modelle$modelle_21_anzahl_gesamt) <- c("Wahlteilnahme, niedrig", "Zeitpunkt, spät", "Schwierigkeit, hoch", "Zufriedenheit, niedrig")

modelsummary(
  modelle$modelle_21_anzahl_gesamt,
  output = "kableExtra",
  fmt = fmt_decimal(digits = 3),
  stars = TRUE,
  estimate = "{estimate}{stars}",  # Entfernt die Standardfehler
  statistic = NULL,  # Entfernt die Standardfehler-Zeile
  gof_map = list(
   list("raw" = "adj.r.squared", "clean" = "Korr. R²", "fmt" = 3),
   list("raw" = "nobs", "clean" = "N", "fmt" = 0)
  ),
  coef_map = c(
    "abweichungen1" = "1 Abweichung",
    "abweichungen2" = "2 Abweichungen",
    "geschlecht" = "Geschlecht",
    "alter" = "Alter",
    "bildung" = "Bildung",
    "politisches interesse" = "Politisches Interesse",
    "pi_staerke" = "Parteiidentifikation, Stärke",
    "(Intercept)" = "Konstante"
  ),
  align = "ldddd"
  ) %>%
  kable_styling(
    latex_options = c("repeat_header", "booktabs", "scale_down", "resize"),
    full_width = FALSE,
    position = "center"
  ) %>%
  row_spec(0, bold = TRUE, align = "c") %>%
  add_footnote(
    label = paste0("Anmerkung: \\textit{+p<0,1; *p<0,05; **p<0,01; ***p<0,001}. \\\\ \\textbf{Datenbasis:} ", notes$notes_21),
    notation = "none",
    escape = FALSE,
    threeparttable = TRUE
  )
vincentarelbundock commented 3 weeks ago

Hi,

This is very easy to achieve with tinytable. See below.

If you need help with kableExtra specifically, you'll need to open an issue on their Github site, or ask on StackOverflow. If you do that, I recommend you craft a minimal example without modelsummary, since this is a pure kableExtra question, and including modelsummary will make it less likely you get a useful answer.

---
format: html
---

```{r}
#| message: false
library(tinytable)
library(modelsummary)

mod <- lm(mpg ~ qsec, mtcars)
tab <- modelsummary(mod)
tab@notes <- list("a" = list(i = 0, j = 2, text = "Hello world"))
tab