I have a multiplot panel with annotations (outside the plots) that I would like to modify.
How can I:
- move the titles (I. and II.) over to the far left?
- change the amount of white space around the titles?
- change the amount of white space around the plots?
(ggplot()
solution preferred)
This is the code (adapted from OP) to get the above plot (removed unneeded code for theme
, etc.):
panelA <- data.frame(
Stage = c("Juvenile", "Juvenile", "Yearling", "Juvenile", "Juvenile", "Yearling","Juvenile", "Juvenile", "Yearling","Juvenile", "Juvenile", "Yearling"),
Individual = c ("A", "A", "A","B", "B", "B","C", "C", "C","D", "D", "D"),
Score = c( 1.4, 1.2, NA,0.4, 0.6, 0.5,-0.3, -0.5, -0.4,-1.4, -1.2, NA))
A<-ggplot(panelA, aes(x = Stage, y = Score, color =Individual, group= Individual)) +
geom_point() +
geom_line()+
geom_smooth(method=lm, se=F, fullrange=TRUE)
panelB <- data.frame(
Stage = c("Juvenile", "Juvenile", "Yearling", "Juvenile", "Juvenile", "Yearling","Juvenile", "Juvenile", "Yearling", "Juvenile", "Juvenile", "Yearling"),
Individual = c ("A", "A", "A","B", "B", "B","C", "C", "C","D", "D", "D"),
Score = c( 1.4, 1.2, 1.3,0.4, 0.6, NA,-0.3, -0.5, NA,-1.4, -1.2, -1.3))
B<-ggplot(panelB, aes(x = Stage, y = Score, color =Individual, group= Individual)) +
geom_point() +
geom_line()+
geom_smooth(method=lm, se=F, fullrange=TRUE)
library(ggplot2)
library(gridExtra)
library(RGraphics)
library(cowplot)
grid.newpage()
# Create layout : nrow = 4, ncol = 2
pushViewport(viewport(layout = grid.layout(4, 2)))
# A helper function to define a region on the layout
define_region <- function(row, col){
viewport(layout.pos.row = row, layout.pos.col = col)
}
#text I want to annotate
t1 <- ggdraw() + draw_label("I. Effects on variance components", fontface='bold')
t2 <- ggdraw() + draw_label("II. Effects on means (mediated via plasticity)", fontface='bold')
# Arrange the plots
print(t1, vp=define_region(1, 1))
print(A, vp = define_region(2, 1))
print(B, vp=define_region(2, 2))
print(t2, vp = define_region(3, 1))
print(A, vp=define_region(4, 1))
print(B, vp = define_region(4, 2))