I have a fairly complex facet_wrap of choropleth maps that share a common legend and separating them into individual plots. I want to add another very simple bargraph into an unused facet area. I thought I could use annotation_custom
as seen here:
https://github.com/hadley/ggplot2/wiki/Mixing-ggplot2-graphs-with-other-graphical-output
p = qplot(1:10, 1:10) + theme_bw()
g = ggplotGrob(qplot(1, 1))
p + annotation_custom(grob = g, xmin = 2, xmax = 7, ymin = 6, ymax = 10)
But this does not seem to size things correctly even when playing with x/y-min/max. It apprears to want to annotate on each facet. Not what I want.
Separating each facet into an individual plot and using gridExtra::grid.arrange
would be difficult because of the shared gradient legend that each facet works together to generate.
plot1 <- ggplot(mtcars, aes(factor(mtcars$gear))) +
geom_bar() +
facet_wrap(~cyl, ncol=2) +
coord_flip()
plot2 <- ggplot(mtcars, aes(as.factor(am))) +
geom_bar(aes(fill=factor(cyl)))
This fails (plots on each facet):
g <- ggplotGrob(plot2)
plot1 + annotation_custom(grob = g, xmin = 0, xmax = 1, ymin = 0, ymax = 1)
Desired look: