There are two ways to plotting multiple graphs in R.
- Create a grid of separate graphs on the same plot
- Overlay all graphs in a single frame of one plot
Create a grid of separate graphs on the same plot
A grid in R is created using the par() command. An example where we plot 4 graphs in a single plot.
> x=seq(-4,4,.1) > par(mfrow=c(2,2)) > plot(x,dt(x,3),'l',col='red') > plot(x,dt(x,5),'l',col='blue') > plot(x,dt(x,10),'l',col='black') > plot(x,dnorm(x),'l',col='magenta')
We generate a vector of values between (-4,+4) called ‘x’ and then feed that into the point distribution function (pdf) of Students t-distribution – df(z,df) – which accepts the z-score and the degrees of freedom (df) to generate the pdf. We plot 3 graphs with df = 3, 5, 10. And then we plot a pdf of the Normal Distribution – pnorm(z). Students t-distribution makes more sense with smaller sample sizes and probably with stock prices which tend to have extreme events.
The 2×2 plots – 4 graphs in 2 rows is made possible by the command par(mfrow=c(2,2)). For a 2×1 matrix of plots, we would have used par(mfrow=(c2,1)).

The graphs all quite different since the Students t-distribution has fatter tails than the Normal Distribution. However, that is not very apparent from the side-by-side graphs. We will need to overlay the graphs on top of each other to see the tiny differences in the graphs.
To return to regular single plot grid use
> par(mfrow=c(1,1))
Overlay all graphs in a single frame of one plot
To overlay multiple plots on each other we start by plotting the first graph with all its axes and labels. The only restriction is that we will need to limit the y-interval between specific values (if x is the independent variable, if y is the independent variable then will need to restrict x-interval). ylim=c(0,0.4) restricts the plot between the y-interval (0,0.4).
> par(mfrow=c(1,1)) > plot(x,dnorm(x),'l',col=1,ylim=c(0,0.4))

Now, we overlay the rest of the plots over this one by looping over pdf of the Students t-distribution with df = 3,5,10 (which we plotted in the previous section).
> for (val in c(3,5,10)){ + par(new=T) + plot(x,dt(x,val),'l',col=val,axes=F,xlab="",ylab="") + }
The overlay is achieved using the par(new=T) command (same as par(new=TRUE)). It tells R that we are plotting a new graph on the same space. We also needed to turn off the axes (axes=F) and the labels for the x-axes and the y-axes (xlab=””,ylab=””). Otherwise, the text of different graphs will overlay on each other and make it look messy. In the resulting graph, we can see the fat tails of the Students t-distribution.