Description Usage Arguments Value Author(s) References Examples
I borrowed this function from a website. I should look for it again and cite properly. This function allow to plot several ggplots in the same devide.
1 |
... |
Plot objects. They can be as many as necesary. They should be plot object that would draw something in a display device. |
plotlist |
List. List of plot objects. They can be as many as necesary. They should be plot object that would draw something in a display device. |
cols |
Numeric value. This should indicate the number of columns to be drawn in the multi plot. |
layout |
Matrix. That should be a matrix to pass to the layout function |
This function doesn't get an object back. It only plot several plot objects in the same device.
Diego Nieto Lugilde
I took this function from the Cookbook for R website (http://www.cookbook-r.com): http://www.cookbook-r.com/Graphs/Multiple_graphs_on_one_page_%28ggplot2%29/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | ##---- Should be DIRECTLY executable !! ----
##-- ==> Define data, use random,
##-- or do help(data=index) for the standard data sets.
## The function is currently defined as
function (..., plotlist = NULL, cols = 1, layout = NULL)
{
require(grid)
plots <- c(list(...), plotlist)
numPlots = length(plots)
if (is.null(layout)) {
layout <- matrix(seq(1, cols * ceiling(numPlots/cols)),
ncol = cols, nrow = ceiling(numPlots/cols))
}
if (numPlots == 1) {
print(plots[[1]])
}
else {
grid.newpage()
pushViewport(viewport(layout = grid.layout(nrow(layout),
ncol(layout))))
for (i in 1:numPlots) {
matchidx <- as.data.frame(which(layout == i, arr.ind = TRUE))
print(plots[[i]], vp = viewport(layout.pos.row = matchidx$row,
layout.pos.col = matchidx$col))
}
}
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.