thomasp85 / patchwork

The Composer of ggplots
https://patchwork.data-imaginist.com
Other
2.46k stars 162 forks source link

Extend patchwork plot arrangement logic to ggplot2's ggsave? #362

Closed karchern closed 4 months ago

karchern commented 4 months ago

Hi,

Patchwork seems to have very robust internal logic concerning the differentiation between the part of the canvas occupied by a plot's vs it's corresponding legend(s). In other words, it neatly arranges plots in grids irrespectively if they have consistent legends or not, which means it must have a clear idea what is a plot and what is a legend, and scale (the arranged) plots accordingly.

I'm interested to understand if the implementation for this in patchwork could be leveraged to enhance ggsave (I know it's ggplot2 but please bear with me): I'd love ggsave to be flexible such that it could be controlled to interpret the width/height parameters to correspond to the plot only rather than the plot + legend. Personally, most of the times when arranging plots (for publication) what I require to tightly control is not the plot + legend dimensions but simply the dimension of the plot itself, and I am assuming some people might have similar needs.

I'm curious what you think and - if you think this is a good idea - if you could point me to the part in the code that is concerned with discerning plot dimensions vs rest since I'd love to issue such as PR

thomasp85 commented 4 months ago

Hi

This has been discussed before, but is sadly not as easy as it sound. To be clear, it is pretty easy to set the plotting area to a specific size, but the size of the surrounding areas are depending on graphics device settings so you get into circular logic when trying to determine the size of the graphics device required to plot something with a specific panel size. Not saying this can't be solved for specific cases but it is certainly way to brittle to ever get into ggplot2

karchern commented 4 months ago

I see, that's a pity. Thanks for the info!