Is there a way to change the heights/lengths of the y-axis for individual facets in a facet_grid
or facet_wrap
?
For example,
library(ggplot2)
ggplot(economics_long[economics_long$variable %in% c("pop", "uempmed"),], aes(date, value)) +
geom_line() +
facet_grid(variable~., scales = "free_y") +
theme(strip.background = element_blank())
In the above plot, I would like the pop time series y-axis height/length to be, say, twice as large as the uempmed y-axis length (2:1), regardless of the fact the two time series have different y-axis scales.
Like what Kohske does here, in a much older version of ggplot2, which doesn't work in ggplot >=2.0.0:
https://kohske.wordpress.com/2010/12/25/adjusting-the-relative-space-of-a-facet-grid/
I know I can specify the argument space = "free"
in facet_grid
, but I don't think that argument can be used to set a 2:1 y-axis ratio?
I also don't want to use a "grid.arrange type" solution for lining up separately created ggplots (where I can make the 2 separate plots with different y-axis lengths), because I would ideally like to make use of Shiny's interactive ggplot2 features in this one single facet_wrap
plot (e.g. an interactive shiny facet example with a brush is half way down the page here: http://shiny.rstudio.com/articles/selecting-rows-of-data.html).