multiplot: Combine Multiple Graphs into One Plot

Description Usage Arguments Value Note Author(s) See Also Examples

Description

Takes a set of plots and combines them into one ‘multiplot’, allowing the user to specify how the graphs are laid out across the rows and columns of the plot. Specifically designed to overcome problems with more standard approaches to creating multiplots using ggplot2 graphs.

Usage

1
multiplot(..., plotlist=NULL, cols=1, layout=NULL)

Arguments

...

A series of comma-separated plots. E.g. plot1, plot2, plot3

plotlist

A list data object comprising a series of plots. E.g. list(plot1, plot2, plot3)

cols

Numeric. The number of columns that the multiplot should use when arranging the plots. The default is 1.

layout

A Grid layout object which splits the viewport into subregions, specifies the order in which the graphs should be plotted (by row; by column), and specifies which cells in the layout should be occupied by each graph. E.g. matrix(1,2,3,3), nrow=2, byrow=TRUE. See viewport for further details.

Value

Returns one plot.

Note

Closely based upon http://www.cookbook-r.com/Graphs/Multiple_graphs_on_one_page_(ggplot2)/

Author(s)

Paul Williamson

See Also

grid; viewport

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
## Create some ggplot graphs
load.package("ggplot2")
plot1 <- ggplot(data=survey) + geom_bar(aes(x=Health))
plot2 <- ggplot(data=survey) + geom_bar(aes(x=Tenure))
plot3 <- ggplot(data=survey) + geom_bar(aes(x=Age))

## Combine multiple ggplots in one plot
multiplot(plot1, plot2, plot3)

## Change number of columns used to create plot
multiplot(plot1, plot2, plot3, cols=2)

## Pass the plots as a list of plots
plots <- list(plot1, plot2, plot3)
multiplot(plotlist=plots, cols=3)

## Specify which cells in plot grid each plot occupies
multiplot(plotlist=plots, layout=matrix(c(1,2,3,3), nrow=2, byrow=TRUE))

DrPaulWilliamson/ENVS450 documentation built on May 9, 2019, 3:23 a.m.