I am struggling to generate a plot that has 9 subcategories in 2 categories and that should fit on one half of an A4 page.
I have tried to use two facet labels, but the arrangement of the subplots becomes a problem and not every subplot needs to be labeled. I have tried facet, grid.arrange, ggarrange, and cowplot, but I have not managed to remove the white space between subplots and control the labeling.
Any advice on how to approach this would be great; I really want to avoid putting it in a paint program and doing it by hand (non-reproducible).
I am trying to generate a plot that looks something like this:
But I am using this:
inter_plots <- function(data, x_id, y_id, xlab, ylab, xmin, xmax){
ggplot(data, aes_string(x_id, y_id, fill = "probs")) +
geom_tile(color = "white", lwd = 0, linetype = 1) +
scale_x_continuous(expand = c(0, 0), breaks = c(-0.5, 0, 1, 2)) +
scale_y_continuous(expand = c(0, 0),
breaks = c(min(data$sqrt_ud),8.867e-07,1.755e-06),
labels = my_labels) +
labs(x = "", y = "", fill = "Selection \nprobability") +
scale_fill_gradientn("Selection \nprobability", colors = colfunc(135)) +
theme_classic() +
theme(axis.text = element_text(color = "black", size = 15),
axis.line = element_line(linewidth = 1.2),
text = element_text(size = 20),
legend.text = element_text(size = 15),
legend.position = "none",
aspect.ratio = 1,
axis.title.x=element_text(color = "white"),
axis.text.x=element_text(color = "white"),
axis.ticks.x=element_blank(),
plot.margin=unit(c(-1,1,-1,0), "cm"))
}
to generate individual plots and arrange them in gridExtra:
gridExtra::grid.arrange(fall_plots[[1]], spring_plots[[1]], fall_plots[[2]], spring_plots[[2]], fall_plots[[3]], spring_plots[[3]],
fall_plots[[4]], spring_plots[[4]], fall_plots[[5]], spring_plots[[5]], fall_plots[[6]], spring_plots[[6]], fall_plots[[7]], spring_plots[[7]],
fall_plots[[8]], spring_plots[[8]], fall_plots[[9]],
ncol = 2, nrow = 9, left = yleft, bottom = xbottom,
vp = viewport(width=0.9, height=0.9))
Thanks!


Your problem is simply that your plotting window has too wide an aspect ratio. Because you have set your plots' aspect ratios to 1, you need to ensure that your output device exactly matches the layout you want.
Obviously, we don't have your data, but let's generate 18 random plots with a fixed aspect ratio:
Now if I set my plotting window to 1488 x 1880 pixels, there has to be whitespace left over because of the fixed aspect ratio of the plots:
But if I change my plotting dimensions to 500 x 1880 pixels, I lose most of the excess whitespace:
The best way to remove whitespace altogether is to remove
aspect.ratio = 1from your ggplot code. This will result in all the whitespace being removed. You then just adjust the dimensions of your plotting window to make the individual panels appear square.