jthomasmock / gtExtras

A Collection of Helper Functions for the gt Package.
https://jthomasmock.github.io/gtExtras/
Other
193 stars 26 forks source link

Splitting up Tables #6

Closed arjunmenon10 closed 2 years ago

arjunmenon10 commented 3 years ago

Trying to figure out ways to split up tables (16 teams in each column) to make tables more readable without using magick function

jthomasmock commented 3 years ago

Hi @arjunmenon10

I believe this resolved with the addition of:

gt_double_table() and gt_two_column_layout().

https://jthomasmock.github.io/gtExtras/reference/gt_double_table.html https://jthomasmock.github.io/gtExtras/reference/gt_two_column_layout.html

Can you check out those functions, and let me know if they solve the problems you have?

Thanks!

library(gt)
library(dplyr)

# add row numbers and drop some columns
my_cars <- mtcars %>%
  dplyr::mutate(row_n = dplyr::row_number(), .before = mpg) %>%
  dplyr::select(row_n, mpg:drat)

# create a one-argument function, passing data to `gt::gt()`
my_gt_fn <- function(x){
  gt(x) %>%
    gtExtras::gt_color_rows(columns = row_n, domain = 1:32)
}

# pass data, your function and the nrows
my_tables <- gt_double_table(my_cars, my_gt_fn, nrows = nrow(my_cars)/2)

# boom, this will return it to the viewer
my_output <- gt_two_column_layout(my_tables)
my_output

jthomasmock commented 2 years ago

Hi @arjunmenon10 - I'm going to close this issue now. Please open it again if you have further issues.