-
Notifications
You must be signed in to change notification settings - Fork 128
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
Options for another kind of stacking? #2006
Comments
Maybe if we added a new function (something like |
In the following, I'm thinking about creating a grid of tables, each already containing a There are two approaches to merging/stacking:
For my own use, I've written a wrapper around Ultimately I can see use cases for both approaches and would love to see both implemented. As always, Just in case my discussion of a grid cell with missing data isn't clear enough, I've added an example... library(tidyverse)
data <- palmerpenguins::penguins |>
filter(!is.na(sex)) |>
filter( !(species=='Chinstrap' & year==2007) ) |> # remove a group
select(body_mass_g, sex, species, island, year)
# Adelie penguins are on all three islands, so there will be 3 columns
A_2007 <- gtsummary::tbl_summary(
data |>
filter(species == 'Adelie', year == 2007) |>
select(body_mass_g, sex, island),
by=island
)
A_2008 <- gtsummary::tbl_summary(
data |>
filter(species == 'Adelie', year == 2008) |>
select(body_mass_g, sex, island),
by=island
)
# Chinstrap penguins are only on Dream island.
#
# This blows up so in my looping, I have to double check if there is data
# C_2007 <- gtsummary::tbl_summary(
# data |>
# filter(species == 'Chinstrap', year == 2007) |>
# select(body_mass_g, sex, island),
# by=island
# )
C_2008 <- gtsummary::tbl_summary(
data |>
filter(species == 'Chinstrap', year == 2008) |>
select(body_mass_g, sex, island),
by=island
)
# Gentoo's are only on Biscoe Island
G_2007 <- gtsummary::tbl_summary(
data |>
filter(species == 'Gentoo', year == 2007) |>
select(body_mass_g, sex, island),
by=island
)
G_2008 <- gtsummary::tbl_summary(
data |>
filter(species == 'Gentoo', year == 2008) |>
select(body_mass_g, sex, island),
by=island
)
R_2007 <- gtsummary::tbl_merge(
list(A_2007,G_2007),
tab_spanner=c('Adelie','Gentoo') )
R_2008 <- gtsummary::tbl_merge(
list(A_2008, C_2008, G_2008),
tab_spanner=c('Adelie','Chinstrap','Gentoo') )
# Now the stack is all messed up even ignoring the N counts
gtsummary::tbl_stack(
list(R_2007, R_2008),
group_header=c('2007','2008'))
#> Column headers among stacked tables differ. Headers from the first table are
#> used.
#> ℹ Use `quiet = TRUE` to suppress this message.
Created on 2024-10-10 with reprex v2.1.1 |
Rather than using the row headers in gt (and for the other print engines, just adding a new column to the left), I would like to be able to stack tables and have the individual tables indented with the headers.
I also want this somehow integrated with
tbl_strata()
for stacking, but haven't thought through all those details yet.The text was updated successfully, but these errors were encountered: