R Plots Par

xpresscodes
3 min readSep 20, 2021

--

>>> Register here <<<

In this article, you will learn to use par() function to put multiple graphs in a single plot by passing graphical parameters mfrow and mfcol.

  1. Par Mar In R
  2. R Plot Par Margins
  3. R Plot Parametric Curve
  4. Par Function R Studio

Examples x-c(2.2, 3, 3.8, 4.5, 7, 8.5, 6.7, 5.5) y-c(4, 5.5, 4.5, 9, 11, 15.2, 13.3, 10.5) # Plot points plot(x, y) # Change plotting symbol # Use solid circle plot(x, y, pch = 19). By default pch=1. The following arguments can be used to change the color and the size of the points. Col: color (code or name) to use for the points; bg: the background (or fill) color for the open plot symbols. There are 2 margin areas in base R plots: margin and oma.You can control their size calling the par function before your plot and giving the corresponding arguments. Mar for margin. Oma for outer margin area. For both arguments, you must give four values giving the desired space in the bottom, left, top and right part of the chart respectively.

Sometimes we need to put two or more graphs in a single plot.

R par() function

We can put multiple graphs in a single plot by setting some graphical parameters with the help of par() function. R programming has a lot of graphical parameters which control the way our graphs are displayed.

The par() function helps us in setting or inquiring about these parameters. For example, you can look at all the parameters and their value by calling the function without any argument.

You will see a long list of parameters and to know what each does you can check the help section ?par. Here we will focus on those which help us in creating subplots.

Graphical parameter mfrow can be used to specify the number of subplot we need.

It takes in a vector of form c(m, n) which divides the given plot into m*n array of subplots. For example, if we need to plot two graphs side by side, we would have m=1 and n=2. Following example illustrates this.

This same phenomenon can be achieved with the graphical parameter mfcol.

The only difference between the two is that, mfrow fills in the subplot region row wise while mfcol fills it column wise.

Same plot with the change par(mfcol = c(2, 2)) would look as follows. Note that only the ordering of the subplot is different.

More Precise Control

The graphical parameter fig lets us control the location of a figure precisely in a plot.

We need to provide the coordinates in a normalized form as c(x1, x2, y1, y2). For example, the whole plot area would be c(0, 1, 0, 1) with (x1, y1) = (0, 0) being the lower-left corner and (x2, y2) = (1, 1) being the upper-right corner.

R plot parabola

Par Mar In R

Note: we have used parameters cex to decrease the size of labels and mai to define margins.

R Plot Par Margins

The numbers assigned to fig were arrived at with a hit-and-trial method to achieve the best looking plot.

R Plot Parametric Curve

Par Function R Studio

  • PREVIOUS
    R Plot Function
  • NEXT
    Saving a Plot in R

>>> Register here <<<

--

--