Formatting a 5x2 grid of maps (currently sp)

45 views Asked by At

I am plotting a series of maps using gridExtra and sp. Here is the result. Notice that while I am using 5 different shapefiles (VDS66, 70, 80, 89, 20), 1 per row, I am coloring my maps according to just 2 variables (rice_yields on the left and hyv_ri_prop on the right), and my color breaks are all the same on the left (brky) and all the same on the right (brkh).

I'd like help doing the following: (1) Adding a single colorkey to the bottom of the left column, and another to the bottom of the right column. I.e., i'm currently suppressing them because they are all identical on left and all identical on the right, and so don't need to be repeated. But I want 1 per column, at the bottom. (2) Removing the spacing so that all square are tangential. (I tried this with the widths() and heights() options to no avail.) (3) Adding a title to the left and right column. I tried top = c("Left Title", "Right Title") but this simply centered the left column title. Ideally, (4) using a list + lapply, or a stack, to make this code more efficient. Not critical but would be nice; saw an example here but wasn't sure how to follow it.

I know that that sp package is old, and I don't mind switching to ggpot + sf if that works better. I just haven't yet spend the time to learn how to use these packages, but I should. So please feel free to upgrade if that's more efficient! Thank you.

grid.arrange(spplot(VDS66,zcol="rice_yield",at=brky,col=NA,border=NA,colorkey=FALSE),
             spplot(VDS66,zcol="hyv_ri_prop",at=brkh,col=NA,border=NA,colorkey=FALSE),
             spplot(VDS70,zcol="rice_yield",at=brky,col=NA,border=NA, colorkey = FALSE),
             spplot(VDS70,zcol="hyv_ri_prop",at=brkh,col=NA,border=NA, colorkey = FALSE),
             spplot(VDS80,zcol="rice_yield",at=brky,col=NA,border=NA, colorkey = FALSE),
             spplot(VDS80,zcol="hyv_ri_prop",at=brkh,col=NA,border=NA, colorkey = FALSE),
             spplot(VDS89,zcol="rice_yield",at=brky,col=NA,border=NA, colorkey = FALSE),
             spplot(VDS89,zcol="hyv_ri_prop",at=brkh,col=NA,border=NA, colorkey = FALSE),
             spplot(VDS20,zcol="rice_yield",at=brky,col=NA,border=NA, colorkey = FALSE),
             spplot(VDS20,zcol="hyv_ri_prop",at=brkh,col=NA,border=NA, colorkey = FALSE),
             ncol=2, respect = TRUE)
0

There are 0 answers