Odd question, but I can't seem to find a neat way to manage it! I'm making a number of scientific figures in R--each has a whole bunch of plots (via ggplot2) stacked on top of each other (with plot_grid
), matched up along the same x axis. So far so good, and I'm almost ready to export and polish up all of the figures in illustrator.
The last step is to impose limits on each plot such that space between each plot in the stacks is as narrow as possible. I've done it in a first pass way with:
test1<-ggplot(mtcars, aes(mpg, hp)) +
geom_line() +
theme(plot.margin = unit(c(0, 0, 0, 0), "cm"),
axis.line.y.right = element_line(colour = "black", size=1),
axis.line.y.left = element_line(colour = "black", size=1),
axis.ticks.y.right = element_blank(),
axis.text.y.right = element_blank(),
axis.title.x = element_blank(),
axis.ticks.x = element_blank(),
axis.line.x.bottom = element_blank(),
axis.text.x =element_blank(),
axis.line = element_line(colour = "black", size =1),)
test2<-ggplot(mtcars, aes(mpg, drat)) +
geom_line() +
theme(plot.margin = unit(c(0, 0, 0, 0), "cm"),
axis.line.y.right = element_line(colour = "black", size=1),
axis.line.y.left = element_line(colour = "black", size=1),
axis.ticks.y.right = element_blank(),
axis.text.y.right = element_blank(),
axis.title.x = element_blank(),
axis.ticks.x = element_blank(),
axis.line.x.bottom = element_blank(),
axis.text.x =element_blank(),
axis.line = element_line(colour = "black", size =1),)
test3<-ggplot(mtcars, aes(mpg, wt)) +
geom_line() +
theme(plot.margin = unit(c(0, 0, 0, 0), "cm"),
axis.line.y.right = element_line(colour = "black", size=1),
axis.line.y.left = element_line(colour = "black", size=1),
axis.ticks.y.right = element_blank(),
axis.text.y.right = element_blank(),
axis.title.x = element_blank(),
axis.ticks.x = element_blank(),
axis.line.x.bottom = element_blank(),
axis.text.x =element_blank(),
axis.line = element_line(colour = "black", size =1),)
test<- plot_grid(test1, test2, test3, ncol=1, align="v", rel_heights = c(1,1,1))
test
It looks like something I've done in the theme bit. Not sure--but help would be appreciated!