-
Notifications
You must be signed in to change notification settings - Fork 209
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 row spanner label feature #577
Comments
Thanks so much for filing the issue over here. It's a really great idea and one that will be implemented sooner than later! |
Agree, this would be awesome! Looking to do the same thing. |
@rich-iannone and @jcheng5, happy to help if needed. I have created a branch to work on this, but any advice with your knowledge of the framework would be very helpful. Particularly I am trying to figure out if dt_spanners could include both the row and column spanners. Not sure how to track row labels, row groups, and summary rows if this approach is used though. Any thoughts/suggestions? |
+1 for this feature! I'm so impressed with gt and thought it had everything... until I looked up how to add a spanner row label. Looking forward to seeing this added! |
Any progress on this? It would be really helpful! |
+1, would really benefit from this functionality as well. |
Has this issue been resolved? |
@edgarakopyan Yes, this is a new feature and is activated in library(gt)
library(tidyverse)
# Get vectors of 2-letter country codes for
# each region of Oceania
Australasia <- c("AU", "NZ")
Melanesia <- c("NC", "PG", "SB", "VU")
Micronesia <- c("FM", "GU", "KI", "MH", "MP", "NR", "PW")
Polynesia <- c("PF", "WS", "TO", "TV")
# Create a gt table based on a preprocessed `countrypops`
countrypops %>%
filter(country_code_2 %in% c(
Australasia, Melanesia, Micronesia, Polynesia)
) %>%
filter(year %in% c(1995, 2005, 2015)) %>%
mutate(region = case_when(
country_code_2 %in% Australasia ~ "Australasia",
country_code_2 %in% Melanesia ~ "Melanesia",
country_code_2 %in% Micronesia ~ "Micronesia",
country_code_2 %in% Polynesia ~ "Polynesia",
)) %>%
pivot_wider(names_from = year, values_from = population) %>%
arrange(region, desc(`2015`)) %>%
select(-starts_with("country_code")) %>%
gt(
rowname_col = "country_name",
groupname_col = "region"
) %>%
tab_header(title = "Populations of Oceania's Countries in 1995, 2005, and 2015") %>%
tab_spanner(
label = "Total Population",
columns = c(`1995`, `2005`, `2015`)
) %>%
fmt_number(
columns = c(`1995`, `2005`, `2015`),
decimals = 0,
use_seps = TRUE
) %>%
tab_options(row_group.as_column = TRUE) Will close this issue now as this was missed when the PR was merged. |
Cool, thanks! |
I realize this issue is closed, but I have a need to have row group that spans across the width of the table and a spanner row that groups row labels into a merged cell. Any advice on this? |
Is there a way to make spanner row labels (similar to spanner column labels, but for rows) or to re-position the row group label to the side?
For example, data with two rows per "group" would be much cleaner with a single group label to the left of the plot than as many small tables stacked vertically (with the row group feature) or with duplicate labels (with the stub feature).
Here is a mock-up of one potential use:
Filed as issue here per request from RStudio community
The text was updated successfully, but these errors were encountered: