I have the following code which generates a list of plots of k=2
classes.
library(ggplot2)
library(cumplyr)
library(scales)
library(reshape2)
library(RColorBrewer)
library(tools)
library(gridExtra)
jet.colors <- colorRampPalette(c("#00007F", "blue", "#007FFF", "cyan","#7FFF7F", "yellow", "#FF7F00", "red", "#7F0000"))
myPalette <- colorRampPalette(rev(brewer.pal(11, "Spectral")))
x = 1:50
y = 1:50
pts = cartesian_product(c('x','y'))
make_df <- function(i) {
k = if(i <= 5) 1 else 2
d1 = cbind(pts, runif(nrow(pts),min=0,max=10*i), 1)
colnames(d1) = c("x","y","val", "k")
return(d1)
}
dflist = lapply(as.list(1:10),make_df)
make_plot <- function(data, gmin = 0, gmax = 100) {
p1 <- ggplot(data)
p1 <- p1 + geom_tile(aes(x = x, y = y, fill = val))
p1 <- p1 + scale_fill_gradientn(colours = myPalette(gmax), limits=c(gmin,gmax))
return(p1)
}
plotlist = lapply(dflist, make_plot)
g = do.call(arrangeGrob, plotlist)
I am having trouble with the final arranging of the plot. The plots can be of type k=1 or type k = 2. I would like to:
- arrange the plots in a 2 x 5 grid,
- have only 1 legend
- Label each row of plots with the appropriate k value
- Have the plots along the row quote close to each other, perhaps just a small gap between each
I have been spinning my wheels with this for a few hours to no avail!
Thanks!