patchwork icon indicating copy to clipboard operation
patchwork copied to clipboard

Set table theme based on ggplot2 theme?

Open thomasp85 opened this issue 1 year ago • 5 comments

It could be pretty nifty if we could derive a nice compatible theming of gt tables from a complete ggplot2 theme...

thomasp85 avatar Sep 10 '24 06:09 thomasp85

It may be hard because the intent of the theme is not always obvious from its parts. E.g. theme_minimal() has the intention of minimalism but there is no obvious way to deduce that other than looking at it's effect on a plot

thomasp85 avatar Sep 10 '24 06:09 thomasp85

@teunbrand any ideas for this?

thomasp85 avatar Sep 10 '24 06:09 thomasp85

I had a bit of an experiment going with more formally putting gt tables as legends/axes. The code I used to homogenise styling lives here: https://github.com/teunbrand/gtguides/blob/138c17c177c03e64624052f88a4875592dbff2d6/R/gtlegend.R#L197-L240 However, this is a first draft and doesn't really cover everything.

It'd be easier if tables had dedicated ggplot2 theme elements to deal with table specific stuff like stripes and such. The question however is where these theme settings should live. {gt} has no dependency on {ggplot2} and {ggplot2} has no intrinsically motivated reason to incorporate such elements.

teunbrand avatar Sep 10 '24 07:09 teunbrand

Perhaps too specifically, I've also had some more detailed ideas.

  • We could use the plot.background and panel.background to have alternating colours for striping. This would mean theme_gray() has striping but theme_minimal() does not.
  • The panel.grid could determine what the body cell borders looks like, so theme_minimal() would have light gray borders, theme_gray() white borders (that only show up on striped cells) and theme_classic() would have no borders.
  • The panel.border could be used for the first and last borderlines that set apart the table body.

teunbrand avatar Sep 10 '24 07:09 teunbrand

Yeah, I was thinking something along those lines but I'm still unsure whether the end result would feel "native" to the plot.

thomasp85 avatar Sep 10 '24 08:09 thomasp85