how to give a title to each column created with grid.arrange() in R?
Asked Answered
C

1

10

Does anyone know if it is possible to give a title at each column of graphs created with grid.arrange()? I know that is possible to give an overall title and a title to each graph but I would need only a column title. Thank you very much!

grid.arrange(c1b, c2a, c3d, c2b, c3a, c2d, c3b, c1a, c1d, ncol=3, nrow=3)
Cheroot answered 17/4, 2016 at 14:26 Comment(3)
you could use nested arrangeGrob calls for each column and set the top argument in eachSacchariferous
how would you modify this code?Cheroot
grid.arrange( arrangeGrob(p1, p2, top="A"), arrangeGrob(p3, p4, top="B"), ncol=2) - change t suit your QSacchariferous
D
2

Credit to user20650:

library(tidyverse)
library(gridExtra)

#create a bunch of line graphs with the mtcars dataset
graph1 <- ggplot(mtcars, aes(x = mpg, y = disp)) + geom_line()
graph2 <- ggplot(mtcars, aes(x = mpg, y = hp)) + geom_line()
graph3 <- ggplot(mtcars, aes(x = mpg, y = drat)) + geom_line()
graph4 <- ggplot(mtcars, aes(x = mpg, y = wt)) + geom_line()

grid.arrange(arrangeGrob(graph1, graph2, top = "Column A"),
             arrangeGrob(graph3, graph4, top = "Column B"), ncol = 2)

four line graphs, laid out in a grid, with columns

Debarath answered 17/6, 2023 at 12:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.