Multiple plot function

From: http://www.cookbook-r.com/Graphs/Multiple_graphs_on_one_page_(ggplot2)/

library(ggplot2)

multiplot(p1, p2, p3, p4, cols=2)

# Multiple plot function
#
# ggplot objects can be passed in ..., or to plotlist (as a 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.
#
multiplot <- function(..., plotlist=NULL, file, cols=1, layout=NULL) {
library(grid)

# Make a list from the ... arguments and plotlist
plots <- c(list(...), plotlist)

numPlots = length(plots)

# If layout is NULL, then use ‘cols‘ to determine layout
if (is.null(layout)) {
# Make the panel
# ncol: Number of columns of plots
# nrow: Number of rows needed, calculated from # of cols
layout <- matrix(seq(1, cols * ceiling(numPlots/cols)),
ncol = cols, nrow = ceiling(numPlots/cols))
}

if (numPlots==1) {
print(plots[[1]])

} else {
# Set up the page
grid.newpage()
pushViewport(viewport(layout = grid.layout(nrow(layout), ncol(layout))))

# Make each plot, in the correct location
for (i in 1:numPlots) {
# Get the i,j matrix positions of the regions that contain this subplot
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))
}
}
}

时间: 2024-08-04 04:58:19

Multiple plot function的相关文章

The plot Function in matlab

from http://pundit.pratt.duke.edu/wiki/MATLAB:Plotting The plot Function The plot function is used to plot sets of data on a 2-D grid. What follows comes from MATLAB's help function in MATLAB R2009a[1] (some paragraphs have been snipped out). The lin

OPEN CASCADE Multiple Variable Function

OPEN CASCADE Multiple Variable Function [email protected] Abstract. Multiple variable function with gradient and Hessian matrix is very very import in OPEN CASCADE optimization algorithms. In order to understand these optimization algorithm better, l

R的基本绘图包-plot函数

R的plot 既可以绘制点,也可以绘制直方图,还可以绘制箱线图,感觉的确很智能. > b <- c("P", "P", "P" ,"Q", "Q", "Q") > c <- c("TQ","AQ","CQ","BQ","XQ", "XQ") &g

斯坦福大学机器学习公开课---Programming Exercise 1: Linear Regression

斯坦福大学机器学习公开课---Programming Exercise 1: Linear Regression 1  Linear regression with one variable In thispart of this exercise, you will implement linear regression with one variableto predict profits for a food truck. Suppose you are the CEO of a rest

《R in Nutshell》 读书笔记(连载)

R in Nutshell 前言 例子(nutshell包) 本书中的例子包括在nutshell的R包中,使用数据,需加载nutshell包 install.packages("nutshell") 第一部分:基础 第一章 批处理(Batch Mode) R provides a way to run a large set of commands in sequence and save the results to a file. 以batch mode运行R的一种方式是:使用系统

【R】多元线性回归

R中的线性回归函数比较简单,就是lm(),比较复杂的是对线性模型的诊断和调整.这里结合Statistical Learning和杜克大学的Data Analysis and Statistical Inference的章节以及<R语言实战>的OLS(Ordinary Least Square)回归模型章节来总结一下,诊断多元线性回归模型的操作分析步骤. 1.选择预测变量 因变量比较容易确定,多元回归模型中难在自变量的选择.自变量选择主要可分为向前选择(逐次加使RSS最小的自变量),向后选择(逐

翻译文章

王佳佳(主要负责翻译)   张月娥(主要负责神经网络的编辑) 丁选(主要负责向量机的编辑) 6. Classification (II) –Neural Network and SVM 分类-神经网络与支持向量机 Introduction Most research has shown that support vector machines (SVM) and neural networks (NN) are powerful classification tools, which can b

MatLab~Help Document

维基百科 创建数组 To create an array with four elements in a single row, separate the elements with either acomma (,) or a space. a = [1 2 3 4]%行向量 All MATLAB variables are multidimensional arrays, no matter what type of data. A matrix is a two-dimensional a

Learning JavaScript Design Patterns -- A book by Addy Osmani

Learning JavaScript Design Patterns A book by Addy Osmani Volume 1.6.2 Tweet Copyright © Addy Osmani 2015. Learning JavaScript Design Patterns is released under a Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 unported license. It