multiplot: Create Mulitple Plots with ggplots (from Winston Chang)

Description Usage Arguments Examples

View source: R/multiplot.R

Description

This is the Multiple plot function from R-Cookbook. I have merely cleaned up some of the params for my use, added some documentation and examples.

Usage

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

Arguments

...

can pass ggplot objects

plotlist

alternative to ..., list of ggplot objects

cols

Number of columns in layout

layout

A matrix specifying the layout. If present, 'cols' is ignored. If the layout is something like matrix(c(1,2,3,3), nrow=2, byrow=TRUE), then plot 1 will go in the upper left, 2 will go in the upper right, and 3 will go all the way across the bottom.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
x<-rnorm(100)
y<-jitter(x,10000)
img <- readJPEG(system.file('img', 'Rlogo.jpg', package='jpeg'))
xdf<-data.frame(x=x,y=y)
firstplot<-ggplot(xdf,aes(x=x,y=y))+ geom_point()
secondplot<-ggplot(xdf,aes(x=x))+ geom_bar()
thirdplot<-ggplot(xdf, aes(x,y)) + 
annotation_custom(rasterGrob(img, width=unit(1,'npc'), height=unit(1,'npc')), 
                 -Inf, Inf, -Inf, Inf)
thirdplot
svg("test.svg",width=8)
multiplot(thirdplot,secondplot,firstplot,firstplot,layout=matrix(c(1,2,3,4),ncol=4,byrow=F))
dev.off()

USEPA/LakeTrophicModelling documentation built on Oct. 15, 2020, 4:13 p.m.