wilkelab / cowplot

cowplot: Streamlined Plot Theme and Plot Annotations for ggplot2
https://wilkelab.org/cowplot/
701 stars 84 forks source link

Feature request: options for anchors of labels in plot_grid #188

Closed NilsPetras closed 1 year ago

NilsPetras commented 1 year ago

Good day,

For better positioning of labels in plot_grid, I suggest to introduce variable anchors. Specific anchors relative to the grid (center, center top, center left, ...) and the text labels (center, center left - to imitate different flush options) would be ideal. Currently, the position of the labels is highly font size dependent and flush left is sensitive to variation in the width of letters (see example). Since hjust and vjust are not transparently scaled and there seem to be margins in play that cannot easily be changed, it is extremely difficult to align labels when combining multiple plots.

Minimal example: (Note that the labels move both vertically and horizontally when the font sizes changes, and their horizontal placement differs based on string length.)

library(ggplot2)
library(cowplot)
plot1 <- ggplot(mtcars, aes(x = mpg, y = cyl)) + geom_point()
plot_grid(plotlist = list(plot1, plot1),
          labels = c("asdfghjkl", "asdf"),
          label_size = 40)
plot_grid(plotlist = list(plot1, plot1),
          labels = c("asdf", "asdfghjkl"),
          label_size = 40)
plot_grid(plotlist = list(plot1, plot1),
          labels = c("asdfghjkl", "asdf"),
          label_size = 5)

Because I think that a fundamental overhaul of the positioning of these labels would be very helpful, I wrote a feature request and not a bug report. But of course a quick fix of some of the issues would already be much welcome!

Thank you for your great work so far, Nils

clauswilke commented 1 year ago

https://stackoverflow.com/a/47724512/4975218