Description Usage Arguments Details Value Author(s) Examples
ggplot objects can be passed in ..., or to plotlist (as a list of ggplot objects)
1 2 3 |
... |
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 |
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.
NULL (invisibly)
A. Teucher, borrowed and modified from http://www.cookbook-r.com/Graphs/Multiple_graphs_on_one_page_(ggplot2)/
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.