Including multiple grid graphs

I wonder if anyone can tell me a way to organize several graphs created with a grid in the grid.

Example:

library(lattice) attach(mtcars) # create factors with value labels gear.f<-factor(gear,levels=c(3,4,5), labels=c("3gears","4gears","5gears")) cyl.f <-factor(cyl,levels=c(4,6,8), labels=c("4cyl","6cyl","8cyl")) # kernel density plot a<-densityplot(~mpg, main="Density Plot", xlab="Miles per Gallon") 

Ok, so I created the plot.

After reading the previous post, I found out how to arrange this in a grid with grid.arranje

 library(latticeExtra) library(gridExtra) grid.arrange(a,a, nrow=2,ncol=2) 

I want to create a graph with two graphs in the first row, two graphs in the second and three graphs in the third and fourth row.

I tried the following: the witch is not working

 grid.arrange(a,a,a,a,ncol=2,(arrangeGrob(a,a,a,a,a,a,ncol=2))) 

Is it possible that I want starting with my code?

+4
source share
1 answer

With gridExtra,

 library(gridExtra) a <- rectGrob(gp=gpar(fill="grey90")) row12 <- arrangeGrob(a, a, a, a, ncol=2) row34 <- arrangeGrob(a, a, a, a, a, a, ncol=3) grid.arrange(row12, row34, ncol=1) 

enter image description here

+3
source

Source: https://habr.com/ru/post/1488298/


All Articles