multiplot | R Documentation |
ggplot objects can be passed in ..., or to plotlist (as a list of ggplot objects)
multiplot(
...,
plotlist = NULL,
cols = 1,
layout = NULL,
widths = NULL,
heights = NULL,
title = NULL,
titlefont = "",
titleface = 1,
titlesize = 16
)
... |
Two or more ggplot2 objects. |
plotlist |
A list of ggplot2 objects (optional). |
cols |
Number of columns in layout. |
layout |
A matrix specifying the layout. If present, 'cols' is ignored. |
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. |
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.
This extends the multiplot function by Winston Chang in the Cookbook for R.
NULL (invisibly)
## 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.