library(gt)
# APA style ####
gt_apastyle <- function(gt_table, font.size=12) {
gt_table |>
gt::opt_table_lines(extent = "none") %>%
gt::tab_options(
heading.border.bottom.width = 2,
heading.border.bottom.color = "black",
heading.border.bottom.style = "solid",
table.border.top.color = "black",
table.border.top.style = "solid",
table.border.top.width = 2,
table_body.hlines.color = "white",
table_body.border.top.color = "black",
table_body.border.top.style = "solid",
table_body.border.top.width = 2,
heading.title.font.size = font.size,
table.font.size = font.size,
heading.subtitle.font.size = font.size,
table_body.border.bottom.color = "black",
table_body.border.bottom.width = 2,
table_body.border.bottom.style = "solid",
column_labels.border.bottom.color = "black",
column_labels.border.bottom.style = "solid",
column_labels.border.bottom.width = 1,
latex.use_longtable = FALSE
) |>
gt::opt_table_font(font = "times")
}
make_age <- function(age) {
age <- as.numeric(age)
mean(age, na.rm = TRUE) |>
insight::format_value(digits=1) |>
paste0(" ± ",
insight::format_value(sd(age, na.rm = TRUE), digits=1))
}
# Create the dataframe
table <- data.frame(
Sample = c('', 'Sample 1a', 'Sample 1b', 'Sample 2', 'Sample 3', 'Sample 4', 'Sample 5', 'Sample 6', '', 'Sample 7a', 'Sample 7b', 'Sample 7c', '', 'Sample 8a', 'Sample 8b', 'Sample 9', 'Sample 10', 'Sample 11', 'Sample 12', 'Sample 13', 'Sample 14', 'Sample 15', 'Sample 16', 'Sample 17', 'Sample 18'),
Reference = c('Murphy et al., (2020)', '', '', 'Gaggero et al., (2021)', 'Campos et al., (2022)', 'Todd et al., (2022)', 'Arslanova et al., (2022)', 'Brand et al., (2022)', 'Brand et al., (2023)', '', '', '', 'Lin et al., (2023)', '', '', 'VonMohr et al., (2023)', 'Makowski et al., (2023a)', 'Makowski et al., (2023b)', 'Makowski et al., (2023c)', 'Makowski et al., (2024)', 'Poerio et al., (2024)', 'Poerio et al., unpublished', 'Arjona et al., unpublished', 'Petzke et al., (2024)', 'Total'),
Language = c('', 'English', 'English' , 'English and Italian', 'Portuguese', 'English', 'English', 'German', '', 'German', 'German', 'German', '', 'Chinese', 'Chinese', 'English', 'English', 'English', 'English', 'English', 'English', 'English','English', 'German', ''),
N = c('', nrow(df1a), nrow(df1b), nrow(df2), nrow(df3), nrow(df4), nrow(df5_attention), nrow(df6),'', nrow(df7a), nrow(df7b), 802,'', nrow(df8a), nrow(df8b), nrow(df9), nrow(df10), nrow(df11), nrow(df12), nrow(df13), nrow(df14), nrow(df15), nrow(df16), nrow(df17), 33526),
'Difference' = c('','', '', '', '', '', '', '', '', '', '', '', '', 'Collapsed "Itch" and "Tickling"', 'Collapsed "Itch" and "Tickling"', '', 'Analog scales. No Temperature, Blood sugar and Cough items', 'Analog scales', 'Analog scales', '', '', '', '', '', ''),
Age = c('', make_age(df1a$Age), make_age(df1b$Age), make_age(df2$Age), make_age(df3$Age), "48.6.6 ± 14.1*", make_age(df5_attention$Age), make_age(df6$Age),'', make_age(df7a$Age), make_age(df7b$Age), make_age(df7c$Age),'', make_age(df8a$Age), make_age(df8b$Age), make_age(df9$Age), make_age(df10$Age), make_age(df11$Age), make_age(df12$Age), make_age(df13$Age), make_age(df14$Age), make_age(df15$Age), make_age(df16$Age), make_age(df17$Age), '47.96 ± 13.1'),
Range = c('', '18-69', '18-91', '18-58', '18-72', '18-92*', '18-73', '18-78', '', '18-79', '16-81', '18-72','', '16-60', '20-60', '18-93', '18-73', '17-76','18-50', '17, 87', '18-57', '18-60', '18-79', '22-69', '17-93'),
Female_Percentage = c('', '69.4%', '70.1%', '60.3%', '59.6%', '50%*', '46.8%', '78.7%', '', '79.5%', '77.7%', '68.9%', '', '57.0%', '56.2%', '73.2%', '50.3%', '53.0%', '76%', '57.3%', '74.8%', '75.9%', '67.7%', '68.5%', '71.3%'),
Availability= c('osf.io/3m5nh', '', '', 'osf.io/5x9sg', 'osf.io/j6ef3', 'osf.io/ms354', 'osf.io/mp3cy', 'osf.io/xwz6g', 'osf.io/3f2h6', '', '', '','osf.io/3eztd','', '', 'osf.io/7p9u5', 'github.com/RealityBending/IllusionGameReliability', 'github.com/DominiqueMakowski/PHQ4R', 'github.com/RealityBending/InteroceptionPrimals',
'github.com/RealityBending/InteroceptionScale',
'osf.io/49wbv', '','', 'osf.io/seru4', '')
)
table_apa <- table |>
gt() |>
cols_align(align = c("right"), columns = "Age") |>
cols_label(Age = "Age (Mean ± SD)", Female_Percentage = "Female %") |>
tab_footnote("Note.*Information taken from the sample description of relevant paper rather than recomputed.")
gt_apastyle(table_apa, font.size=12)
# gtsave(gt_apastyle(table_apa, font.size=9), "figures/table1.tex")
saveRDS(table, "figures/table1.rds")
# gtsave(table_apa, "figures/table1.png")