library(ggplot2)
library(gridExtra)
# load iris dataset
data(iris)
# create a list of four barplots
plots <- list()
for (i in 1:4) {
p <- ggplot(iris, aes(x = Species, y = iris[, i])) +
geom_bar(stat = "summary", fun.y = "mean", fill = "steelblue") +
ggtitle(colnames(iris)[i])
plots[[i]] <- p
}
## Warning in geom_bar(stat = "summary", fun.y = "mean", fill = "steelblue"): Ignoring unknown parameters: `fun.y`
## Ignoring unknown parameters: `fun.y`
## Ignoring unknown parameters: `fun.y`
## Ignoring unknown parameters: `fun.y`
# create a list of four tables
tables <- list()
for (i in 1:4) {
t <- round(tapply(iris[, i], iris$Species, mean), 2)
tables[[i]] <- tableGrob(t, rows = names(t), cols = NULL, theme = ttheme_minimal())
}
# combine barplots and tables into a grid
grid.arrange(plots[[1]], plots[[2]], plots[[3]], plots[[4]],
tables[[1]], tables[[2]], tables[[3]], tables[[4]],
ncol = 4, widths = c(1, 1, 1, 1), heights = c(2, 1))
## No summary function supplied, defaulting to `mean_se()`
## No summary function supplied, defaulting to `mean_se()`
## No summary function supplied, defaulting to `mean_se()`
## No summary function supplied, defaulting to `mean_se()`
