ggtitle height varies with descending letters #2288
I just noticed that the height of a ggplot2 main title depends on the letters used. Although there is no difference in the title height (and therefore the dimensions of the plot itself) between titles with only typical sized letter (e.g. "arrr") or with ascenders (e.g. "brrr"), the title height increases with the inclusion of descenders (e.g. "prrr"). Although I understand that as a workaround I can use all-caps or readjust the plot height with
library(ggplot2) library(gridExtra) grid.arrange(ggplot() + ggtitle("arrr"), ggplot() + ggtitle("brrr"), ggplot() + ggtitle("prrr"), nrow = 1)
Thanks in advance!
The text was updated successfully, but these errors were encountered:
I've run into this problem also and I debugged it in quite some detail. I'm writing up my findings here in the hope they may be useful to somebody. I don't have the time right now to prepare a proper pull request but may be able to do so in the future.
The problem is caused by this line:
A simple fix would be to replace the string in the text grob with a constant string that is always used. This should return the same descent height at all times, only dependent on font metrics and independent on the specific label used. So, we could replace this line:
with these two lines:
to get consistent descent values regardless of the text label shown in the plot.
Here's the effect of this proposed patch.
Note that this also fixes the layout of the legend title.
…2471) * Calculate constant descender heights, regardless of label content. Fixes #2288 * Make themes more visually consistent. Also fix spacing bug for multi-line legend titles. * gracefully handle missing fontsize in theme (e.g., if legend.title has been set to element_blank()) * update vdiffr templates