par(mar, mgp, las)

par(mar=c(5.1, 4.1, 4.1, 2.1), mgp=c(3, 1, 0), las=0)
par sets or adjusts plotting parameters. Here we consider the following three parameters: margin size (mar), axis label locations (mgp), and axis label orientation (las).
  • mar – A numeric vector of length 4, which sets the margin sizes in the following order: bottom, left, top, and right. The default is c(5.1, 4.1, 4.1, 2.1).
  • mgp – A numeric vector of length 3, which sets the axis label locations relative to the edge of the inner plot window. The first value represents the location the labels (i.e. xlab and ylab in plot), the second the tick-mark labels, and third the tick marks. The default is c(3, 1, 0).
  • las – A numeric value indicating the orientation of the tick mark labels and any other text added to a plot after its initialization. The options are as follows: always parallel to the axis (the default, 0), always horizontal (1), always perpendicular to the axis (2), and always vertical (3).

Example. The default values of the three plotting parameters are shown using character strings of their argument names in par (see par(char)), followed by sample code creating four plots, where one additional plotting parameter is modified in each plot. In addition to the individual plots shown below, a 4-page PDF of the plots is available for easier browsing.
> par("mar")
[1] 5.1 4.1 4.1 2.1
> par("mgp")
[1] 3 1 0
> par("las")
[1] 0
> 
> set.seed(5)
> x <- rnorm(200)
> y <- 25 - 22*x + 5*x^2 + rnorm(200)
> 
> png("par-120208-01.png")
> plot(x, y, main="defaults")
> dev.off()
quartz 
     2 
> 
> png("par-120208-02.png")
> par(mar=c(3.5, 3.5, 2, 1))
> plot(x, y, main="par(mar=c(3.5, 3.5, 2, 1))")
> dev.off()
quartz 
     2 
> 
> png("par-120208-03.png")
> par(mar=c(3.5, 3.5, 2, 1), mgp=c(2.4, 0.8, 0))
> plot(x, y, main="par(mar=c(3.5, 3.5, 2, 1), mgp=c(2.4, 0.8, 0))")
> dev.off()
quartz 
     2 
> 
> png("par-120208-04.png")
> par(mar=c(3.5, 3.5, 2, 1), mgp=c(2.4, 0.8, 0), las=1)
> plot(x, y,
+      main="par(mar=c(3.5, 3.5, 2, 1), mgp=c(2.4, 0.8, 0), las=1)")
> dev.off()
quartz 
     2 
The data are reproducible thanks to the set.seed function, and plots were saved to files using the png function.

Leave a Reply