Short version: How to get the value of the margin between axis.text and axix.title?
Long version: I am trying to merge three ggplot graphics. The scale should be consistent, so I am using rbind (with ggplotGrob) to align the first two graphics. But the last one has facets, so it is not possible to use this solution for all three.
My idea is manually set the space between axis.title and axis.text in the third graphic (this can be done using margin with element_text). However, to do that I should get the value of this margin in one of the first two graphics. I believe that this information is available in the ggplotGrob, but I don't know the path to retrieve this value in the grob structure.
Fake code example:
library(ggplot2)
library(gridExtra)
a <- ggplotGrob( ggplot(iris[iris$Species != "setosa",], aes(x=Sepal.Length, y=Petal.Width*100000, color=Species)) + geom_line() + theme(legend.position="none"))
b <- ggplotGrob( ggplot(iris[iris$Species != "setosa",], aes(x=Sepal.Length, y=Petal.Length, color=Species)) + geom_line() + theme(legend.position="none"))
c <- ggplotGrob(ggplot(head(mpg, 100), aes(class)) + geom_bar() + facet_grid(.~manufacturer, scales="free_x"))
g1 <- rbind(a, b, size="first")
grid.arrange(g1, c, ncol=1)
Current result: First two graphics with plot area aligned, but not the last one. result plot
Expected result: The plot area of all three graphics aligned.