multiplot: Plot multiple plots in a single pane

Description Usage Arguments Details Value Author(s) Examples

Description

ggplot objects can be passed in ..., or to plotlist (as a list of ggplot objects)

Usage

1
2
3
multiplot(..., plotlist = NULL, cols = 1, layout = NULL, widths = NULL,
  heights = NULL, title = NULL, titlefont = "", titleface = 1,
  titlesize = 16)

Arguments

...

Two or more ggplot2 objects

plotlist

(optional) a list of ggplot2 objects

cols

Number of columns in layout

layout

A matrix specifying the layout. If present, 'cols' is ignored. See Details

widths

a vector of relative column widths eg. c(3,2)

heights

a vector of relative column heights eg. c(3,2)

title

Optional title as a character string

titlefont

The font of the title

titleface

The font face (1 = normal, 2 = bold, 3 = italic, 4 = bold italic)

titlesize

The size of the title font

Details

If plotting three plots and 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. To save, you must use the desired device (eg png()), or save from the RStudio Viewer.

Value

NULL (invisibly)

Author(s)

A. Teucher, borrowed and modified from http://www.cookbook-r.com/Graphs/Multiple_graphs_on_one_page_(ggplot2)/

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
## Not run: 
library("ggplot2")
plot1 <- ggplot(iris, aes(x = Species, y = Sepal.Length)) + 
   geom_bar(stat = "identity")
plot2 <- ggplot(mtcars, aes(x = mpg, y = disp)) + 
   geom_smooth()
multiplot(plot1, plot2, cols = 2, widths = c(3,2), title = "My two unrelated plots")
multiplot(plot1, plot2, cols = 1, heights = c(10,2), title = "My two unrelated plots")
myplots <- list(plot1, plot2, plot1)
multiplot(plotlist = myplots, layout =matrix(c(1,2,3,3), nrow=2), 
     heights = c(1,3), widths = c(3,4), title = "My three unrelated plots")
## Adjusting fonts
library(extrafont)
loadfonts()
multiplot(plotlist = myplots, layout =matrix(c(1,2,3,3), nrow=2),
          heights = c(1,3), widths = c(3,4), title = "My three unrelated plots", 
          titlefont = "Wingdings", titleface = 4, titlesize = 20)

## End(Not run)

Pakillo/pacotools documentation built on May 7, 2019, 11:56 p.m.