O'Reilly logo

R Graphs Cookbook by Hrishi Mittal

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating multiple plot matrix layouts

In this recipe, we will learn how to present more than one graph in a single image. Pairs plots are one example as we saw in the last recipe, but here we will learn how to include different types of graphs in each cell of a graph matrix.

How to do it...

Let's say we want to make a 2x3 matrix of graphs, made of two rows and three columns of graphs. We use the par() command as follows:

par(mfrow=c(2,3))
plot(rnorm(100),col="blue",main="Plot No.1")
plot(rnorm(100),col="blue",main="Plot No.2")
plot(rnorm(100),col="green",main="Plot No.3")
plot(rnorm(100),col="black",main="Plot No.4")
plot(rnorm(100),col="green",main="Plot No.5")
plot(rnorm(100),col="orange",main="Plot No.6")

How it works...

The par() command is by ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required