multiplot: multiplot

Description Usage Arguments Details Value See Also Examples

Description

Plot more than one ggplot object in a grid fashion, similar to par(). This code is not totally written by Ethan; he adapted it from http://www.cookbook-r.com/Graphs/Multiple_graphs_on_one_page_(ggplot2)/.

Usage

1
2
multiplot(..., plotlist = NULL, ncol = 1, byrow = FALSE, layout = NULL,
  title)

Arguments

...

ggplot objects.

plotlist

A list of ggplot objects.

ncol

How many columns in the grid of plots? Ignored if 'layout' is specified.

byrow

Should plots be printed by rows or by columns? Ignored if 'layout' is specified.

layout

A matrix of indices of plots specifying where in the grid the plots should be printed. See details.

title

A string denoting the title.

Details

If 'layout' is specified, 'ncol' and 'byrow' will be ignored. Each plot will then be printed in the grid location corresponding to the entry/entries in 'layout' which list(s) its index in the function call. E.g. the first plot will be plotted in the grid corresponding to where '1' shows up in 'layout'. If any entry is '0', then nothing will be plotted there. It is possible to have a plot span more than one place in the grid; see the examples.

Value

Nothing is returned; however, the ggplot objects are printed.

See Also

http://www.cookbook-r.com/Graphs/Multiple_graphs_on_one_page_(ggplot2)/ http://stackoverflow.com/questions/10776139/r-grid-layout-title

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
library(ggplot2)
data(pizza.data)
p1 <- ggplot(pizza.data, aes(x = fav_flavor, y = time_to_fu)) + geom_boxplot()
p2 <- ggplot(pizza.data, aes(x = likes_pizza, y = time_to_fu)) + geom_boxplot()
p3 <- ggplot(pizza.data, aes(x = time_to_fu, fill = likes_pizza)) + geom_histogram()
multiplot(p1, p2, p3, layout = matrix(c(1,2,3,3), ncol = 2, byrow = TRUE))
## Will give a warning
## Not run: 
multiplot(plotlist = list(p1, p2, p3), layout = matrix(c(1,2,1,2), ncol = 2, byrow = TRUE))

## End(Not run)

eheinzen/Ethan documentation built on May 3, 2019, 4:32 p.m.