R grid.arrange


grid.arrange() function sets up a gtable layout to place multiple grobs on a page. It is located in package "gridExtra".

arrangeGrob(..., grobs = list(...), layout_matrix, vp = NULL,
name = "arrange", as.table = TRUE, respect = FALSE, clip = "off",
nrow = NULL, ncol = NULL, widths = NULL, heights = NULL, top = NULL,
bottom = NULL, left = NULL, right = NULL, padding = unit(0.5, "line"))
grid.arrange(..., newpage = TRUE)
marrangeGrob(grobs, ..., ncol, nrow, layout_matrix = matrix(seq_len(nrow *
ncol), nrow = nrow, ncol = ncol), top = quote(paste("page", g, "of",
npages)))

layout_matrix: a matrix defines the plots layout
vp: view point

> install.packages("ggplot2", repo="http://cran.r-project.org",dep=TRUE)
> install.packages("gridExtra", repo="http://cran.r-project.org",dep=TRUE)
> library(ggplot2)
> library(gridExtra)
> gg <- ggplot(trees, aes(Height,Volume))
> gg1 <- gg + geom_point(color="green")
> gg2 <- gg + geom_bar(stat="identity",color="blue",fill="red")
> gg3 <- ggplot(trees, aes(Height)) + geom_histogram(bins=20)
> grid.arrange(gg1,gg2,gg3,layout_matrix=rbind(c(1,1),c(2,3)))


> grid.arrange(arrangeGrob(gg1,gg2,ncol=2), gg3)







endmemo.com © 2024  | Terms of Use | Privacy | Home