I want to align Plots with titles with grid.arrange
so that the y-Axis of the two plots matches. If one of the plots has a Title that contains a character with a decender (g,j,y,...) and the other doesn't the plots are misaligned.
Is there an option to fix the size of the element e.g. in element_text
in the theme to line heights including decenders?
An alternative would be to modify the grid-grobs directly with ggplotGrob
but this seems overly complicated.
require(ggplot2)
require(gridExtra)
test <- data.frame(x=1:3, y=1:3)
plot1 <- ggplot(test, aes(x=x, y=y)) +
geom_point() +
ggtitle("asdf")
plot2 <- ggplot(test, aes(x=x, y=y)) +
geom_point() +
ggtitle("asdfg")
grid.arrange(plot1, plot1, nrow=1)
grid.arrange(plot1, plot2, nrow=1)
Notice the slight difference in the alignment of the top border of the plotting area in the second plot. In the first one both are aligned perfectly.