Create Multiple plots in the same window using par() function

To create multiple plots in the same window in the R Language, we first divide the frame into the desired grid by using the mfrow argument of the par() function. Here, we can pass a vector containing a number of rows and columns for the grid as value to argument mfrow and this will divide our frame into a grid of that number of rows and columns.

Syntax:

par( mfrow )

where, 

  • mfrow: determines a vector with row and column values for the grid.

Example:

In this example, basic multiple plots in R Language made using the par() function. Here, we have divided the window into a 3X2 grid and plotted plots in it.

R




# divide window into a 3X2 grid
par( mfrow= c(3,2) )
 
# add plots to window
plot( 1:10 )
plot( 1:20 )
plot( 1:30 )
plot( 1:40 )
plot( 1:50 )
plot( 1:60 )


Output:

How to Use Par Function in R?

In this article, we will discuss how to use the par() function in the R Programming Language.

The par() function is used to set or query graphical parameters. We can divide the frame into the desired grid, add a margin to the plot or change the background color of the frame by using the par() function. We can use the par() function in R to create multiple plots at once. This helps us to create a figure arrangement with fine control.

Similar Reads

Method 1: Create Multiple plots in the same window using par() function

To create multiple plots in the same window in the R Language, we first divide the frame into the desired grid by using the mfrow argument of the par() function. Here, we can pass a vector containing a number of rows and columns for the grid as value to argument mfrow and this will divide our frame into a grid of that number of rows and columns....

Method 2: Increase or Decrease margin Around Plot using par() function

...

Method 3: Change axis and tick label size using par() function

In this method to increase or decrease the margin around the plot in the R Language, the user need to use the mar argument of the par() function. Here, the mar argument takes a vector with all the margin values in the following order: bottom, left, top, right as value. The default is mar = c(5.1, 4.1, 4.1, 2.1)....

Method 4: Change the background color of the window using par() function

...

Contact Us