How do I reset mfrow?

Tim Oltman
2 min readMar 27, 2022
A person’s hands laying sticky notes in a grid.
Photo by Kelly Sikkema on Unsplash

When you are making plots in base R sometimes you will want to create several plots side-by-side or in a grid format. To do that you use par(mfrow = c(nr, nc)) where nr is the number of rows you want, and nc is the number of columns. You can also use mfcol if you want your plots to first go down the columns and then fill in the rows.

Let’s say you wanted to create three plots side-by-side and used par(mfrow = c(1, 3)), but now you want to create a single plot again. Creating this plot, you will find that R will only use the left-hand side of the plotting area. For example, the following code will produce the chart shown in Figure 1.

par(mfrow = c(1, 3))
# some other charts and code here
x <- rnorm(1000, 5, 2)
box(which = "figure") # draws a box around the figure
A histogram chart of x showing the distribution of the random variable with mean 5 and standard deviation 2. The chart fills only 1/3 of the space.
Figure 1. Histogram of x pushed over to the left-hand side.

We would like the see our histogram take up the full space for the plot, and we don’t want subsequent plots to appear in this figure. To do that we can simply reset the value of the mfrow parameter to c(1, 1).

par(mfrow = c(1, 1))

We could alternatively shut down our graphics device by calling the function The next time we created a plot R would start up a new graphics device with the default settings. However, this solution will remove any unsaved plots you’ve made in your session so far.

Either way, the next time we call hist(x) we will see something like Figure 2.

A histogram of x taking up the entire space allocated for the figure.
Figure 2. Histogram of x taking up the entire plot space.

This plot takes up the full area as we wanted.