I’ve recently came across the hafen/geofacet function and was pondering to blog an example. Then, I came across a perfect example, thanks to kanishkamisra for working on the dataset & code and making it available via github here!
There are a multitude of ways in which you can divide the plotting area to get multiple plots.
par(mfrow=c()) is one of the most popular: it’s symmetric and very easy to use, you just need to specify the number of rows and columns.
op <- par(no.readonly = TRUE)
If what you’re looking for is a bit less regular and symmetrical, layout matrix is your friend, and you can control the plotting order of each plotting space through byrow (=T by default)
ex1 <- layout(matrix(c(1:2),1,2),widths=c(0.9,0.1),heights=1)
ex2 <- layout(matrix(c(1,1,2,3),2,2,byrow=T),widths=c(0.9,0.1),heights=1)
layout(matrix(c(2,0,1,3),2,2,byrow=TRUE), widths=c(1,0.3), heights=c(0.3,1), TRUE)
plot(Sepal.Length,Sepal.Width, xlab="Sepal Length", ylab="Sepal Width")
plot(NULL, type = "n", axes=F,xlim = c(0, max(x$counts)), ylim = c(range(x$breaks)))
rect(0, x$breaks[1:(length(x$breaks) - 1)], x$counts, x$breaks[2:length(x$breaks)])
This kind of graph is actually much simpler to do in ggplot2…
Layout matrix also offers much more complicated combinations…
a <- layout(matrix(c(1,1,2,1,1,3,4,5,6),3,3), widths=c(0.5,0.5,0.4), heights=1)
ex4 <- layout(matrix(c(1,2,2,3,3,3,4,4,4,4,5,5,6,6,6,7,7,7,7,8),10,2, byrow=F))