Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add add_stat_label() to the JAMA theme for tbl_svysummary() output #1964

Closed
jaromilfrossard opened this issue Sep 12, 2024 · 3 comments · Fixed by #2045
Closed

Add add_stat_label() to the JAMA theme for tbl_svysummary() output #1964

jaromilfrossard opened this issue Sep 12, 2024 · 3 comments · Fixed by #2045

Comments

@jaromilfrossard
Copy link

jaromilfrossard commented Sep 12, 2024

Hello,

Thank you for creating gtsummary!

It seems that the theme for journals does not apply correctly to the tbl_svysummary() object as it stays the default.

However, it seems that the "compact" theme worked as I expected.

I am using the last CRAN version of gtsummary (2.0.2), with R 4.4.0, on windows.

Thanks you again!

PROBLEM: default theme

# insert reprex here
library(gtsummary)
#> Warning: package 'gtsummary' was built under R version 4.4.1
  
theme_gtsummary_journal("jama")
#> Setting theme "JAMA"
survey::svydesign(~1, data = as.data.frame(Titanic), weights = ~Freq) |>
  tbl_svysummary(by = Survived, percent = "row", include = c(Class, Age))

OK : JAMA theme

library(gtsummary)
#> Warning: package 'gtsummary' was built under R version 4.4.1

theme_gtsummary_journal("jama")

#> Setting theme "JAMA"
as.data.frame(Titanic)|>
  tbl_summary(by = Survived, percent = "row", include = c(Class, Age))

PROBLEM: default + compact theme

library(gtsummary)
#> Warning: package 'gtsummary' was built under R version 4.4.1
theme_gtsummary_compact()
#> Setting theme "Compact"
theme_gtsummary_journal("jama")
#> Setting theme "JAMA"
survey::svydesign(~1, data = as.data.frame(Titanic), weights = ~Freq) |>
  tbl_svysummary(by = Survived, percent = "row", include = c(Class, Age))

OK: JAMA + compact theme

  library(gtsummary)
#> Warning: package 'gtsummary' was built under R version 4.4.1
  theme_gtsummary_compact()
#> Setting theme "Compact"
  theme_gtsummary_journal("jama")
#> Setting theme "JAMA"
as.data.frame(Titanic)|>
  tbl_summary(by = Survived, percent = "row", include = c(Class, Age))
@ddsjoberg
Copy link
Owner

Dear @jaromilfrossard , Thanks for the post.

Can you make a couple of updates/add more information?

  • Please be clear what output you expect and what output you recieved.
  • Also, please use the {reprex} package to create your reproducible examples. When using this tool, you will need to convert the gtsummary to kable so it will print properly, e.g tbl_summary(...) |> as_kable(). For your use case, you may also need the reset_gtsummary_theme() function to reset/remove themes.

@jaromilfrossard
Copy link
Author

Hello,

The difference is in the display of the statistics. From my understanding the JAMA theme displays the statistics with the variable name (eg: "Class, n (%)") not as reference in the footnote.

However, this feature does not seem to apply with tbl_svysummary(). It is visible in the last kable, the "quoted" line is "|Class |NA |NA |", but I would expect "|Class, n (%) |NA |NA |".

I hope it is more clear now.

  library(gtsummary)
#> Warning: package 'gtsummary' was built under R version 4.4.1
  
  reset_gtsummary_theme()
# default theme
survey::svydesign(~1, data = as.data.frame(Titanic), weights = ~Freq) |>
  tbl_svysummary(by = Survived, percent = "row", include = c(Class, Age)) |> 
  knitr::kable()

|Characteristic |No
N = 1,490 |Yes
N = 711 |
|:——————|:—————–|:—————-|
|Class |NA |NA |
|1st |122 (38%) |203 (62%) |
|2nd |167 (59%) |118 (41%) |
|3rd |528 (75%) |178 (25%) |
|Crew |673 (76%) |212 (24%) |
|Age |NA |NA |
|Child |52 (48%) |57 (52%) |
|Adult |1,438 (69%) |654 (31%) |

as.data.frame(Titanic)|>
  tbl_summary(by = Survived, percent = "row", include = c(Class, Age)) |> 
  knitr::kable()

|Characteristic |No
N = 16 |Yes
N = 16 |
|:——————|:————–|:—————|
|Class |NA |NA |
|1st |4 (50%) |4 (50%) |
|2nd |4 (50%) |4 (50%) |
|3rd |4 (50%) |4 (50%) |
|Crew |4 (50%) |4 (50%) |
|Age |NA |NA |
|Child |8 (50%) |8 (50%) |
|Adult |8 (50%) |8 (50%) |

theme_gtsummary_journal("jama")
#> Setting theme "JAMA"

# Here it displays the statistics with the variable: "Class, n (%)"
as.data.frame(Titanic)|>
  tbl_summary(by = Survived, percent = "row", include = c(Class, Age)) |> 
  knitr::kable()

|Characteristic |No
N = 16 |Yes
N = 16 |
|:——————|:————–|:—————|
|Class, n (%) |NA |NA |
|1st |4 (50) |4 (50) |
|2nd |4 (50) |4 (50) |
|3rd |4 (50) |4 (50) |
|Crew |4 (50) |4 (50) |
|Age, n (%) |NA |NA |
|Child |8 (50) |8 (50) |
|Adult |8 (50) |8 (50) |

# Here the statistic is not displayed: "Class, n (%)"
survey::svydesign(~1, data = as.data.frame(Titanic), weights = ~Freq) |>
  tbl_svysummary(by = Survived, percent = "row", include = c(Class, Age)) |> 
  knitr::kable()

|Characteristic |No
N = 1,490 |Yes
N = 711 |
|:——————|:—————–|:—————-|

|Class |NA |NA |

|1st |122 (38) |203 (62) |
|2nd |167 (59) |118 (41) |
|3rd |528 (75) |178 (25) |
|Crew |673 (76) |212 (24) |
|Age |NA |NA |
|Child |52 (48) |57 (52) |
|Adult |1,438 (69) |654 (31) |

Created on 2024-09-13 with reprex v2.1.1

@ddsjoberg
Copy link
Owner

Ah, yes, I see now. Thank you for the report!

@ddsjoberg ddsjoberg changed the title Bug Report: <theme are not applying to tbl_svysummary> Add add_stat_label() to the JAMA theme for tbl_svysummary() output Sep 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants