teunbrand / ggh4x

ggplot extension: options for tailored facets, multiple colourscales and miscellaneous
https://teunbrand.github.io/ggh4x/
Other
534 stars 32 forks source link

Feature request: Axis tables #100

Closed dmuenz closed 1 year ago

dmuenz commented 1 year ago

Thank you for the great package! I have a new feature request: functions/geoms to add axis tables along the x and/or y axes. These are tables of data that align with the axes. E.g., you could have a Kaplan-Meier plot with an x-axis table showing number of subjects at risk over time. Or a plot of mean values over time with an x-axis table showing the corresponding sample sizes and means. (I'm taking the concept and term from SAS, which in PROC SGPLOT has the XAXISTABLE and YAXISTABLE statements, and in PROC SGPANEL has the COLAXISTABLE and ROWAXISTABLE statements). This seems like a major missing feature from ggplot.

Ideally, the axis tables should be able to be placed either outside the axis (e.g., below the x-axis) or inside the axis (e.g., in a new "gutter" area above the x-axis but below the data.)

I'm asking you because of your response to the following stackoverflow question: https://stackoverflow.com/questions/62047359/plot-a-table-of-separate-data-below-a-ggplot2-graph-that-lines-up-on-the-x-axis.

A similar question with a nice solution from user Stefan is here: https://stackoverflow.com/questions/61977439/table-below-x-axis-in-ggplot

Both solutions above use the patchwork package, creating a "main" plot and a "table" plot and then adding them with patchwork. One problem with this it that if I added faceting to the main plot, I'd have to manually add the same faceting to the table plot, rather than that happening automatically. Relatedly, if the faceting creates multiple rows, I'd want the axis tables to stay with their facets, rather than all being, e.g., at the bottom.

Here are some other examples of what I mean.

  1. Two x-axis tables, one outside and one inside: https://documentation.sas.com/api/docsets/grstatproc/9.4/content/images/xaxistable.png
  2. Inside x-axis table with a horizontal separating line: https://blogs.sas.com/content/graphicallyspeaking/files/2014/02/SurvivalPlot_AxisTable_Inside_94_SG.png
  3. Y-axis table in a forest plot: https://support.sas.com/kb/42/addl/fusion_42867_1_forest_plot_vector.gif

No problem if you're not interested or don't have time. I would appreciate though any suggestions for where else I might shop this request around.

teunbrand commented 1 year ago

I think this is a great idea. I've already been working at such an axis guide, see last plot of the README here: https://github.com/teunbrand/gguidance. However, that currently relies on a PR to ggplot2 that isn't merged yet, and the code has slightly drifted, so it currently isn't in a working condition. My plan is to sync the code once the PR is merged.

teunbrand commented 1 year ago

In any case, although I think it is a good idea, it won't appear in ggh4x itself, so I'll close this issue as 'not planned', but take that to mean 'planned elsewhere'.