par(cex.axis, cex.lab, cex.main, cex.sub)

par(cex.axis=1, cex.lab=1, cex.main=1.2, cex.sub=1)
par sets or adjusts plotting parameters. Here we consider the adjustment of sizes for four text values: axis tick labels (cex.axis), x-y axis labels (cex.lab), main title (cex.main), and subtitle (cex.sub). There is also a cex argument, which scales all of these values simultaneously. See also: par(mfrow), par(mar, mgp, las), and par(char).
  • cex.axis – Specify the size of the tick label numbers/text with a numeric value of length 1.
  • cex.lab – Specify the size of the axis label text with a numeric value of length 1.
  • cex.main – Specify the size of the title text with a numeric value of length 1.
  • cex.sub – Specify the size of the subtitle label with a numeric value of length 1.

Example. Five plots are generated, one with the default settings and additional plots with exactly one of the cex.option parameters changed. The title in each plot shows the plotting parameter settings. In addition to the individual plots shown below, a 5-page PDF of the plots is available for an easier comparison of the plot settings.
> set.seed(5)
> x    <- 1:100
> y    <- 0.1*x^2 + 0.2*x - 300 + rnorm(100, sd=100)
> red  <- (y - min(y)) / (max(y) - min(y))
> 
> png("cex-default.png")
> main <- "par(cex.axis=1, cex.lab=1, cex.main=1.2, cex.sub=1)"
> plot(x, y, col=rgb(red, 0.5, 0.25, 0.8), cex=2,
+      pch=19, xlab="x-axis label", ylab="y-axis label",
+      main=main)
> title(sub="subtitle")
> dev.off()
null device 
          1 
> 
> png("cex-axis.png")
> par(cex.axis=2, cex.lab=1, cex.main=1.2, cex.sub=1)
> main <- "par(cex.axis=2, cex.lab=1, cex.main=1.2, cex.sub=1)"
> plot(x, y, col=rgb(red, 0.5, 0.25, 0.8), cex=2,
+      pch=19, xlab="x-axis label", ylab="y-axis label",
+      main=main)
> title(sub="subtitle")
> dev.off()
null device 
          1 
> 
> png("cex-lab.png")
> par(cex.axis=1, cex.lab=2, cex.main=1.2, cex.sub=1)
> main <- "par(cex.axis=1, cex.lab=2, cex.main=1.2, cex.sub=1)"
> plot(x, y, col=rgb(red, 0.5, 0.25, 0.8), cex=2,
+      pch=19, xlab="x-axis label", ylab="y-axis label",
+      main=main)
> title(sub="subtitle")
> dev.off()
null device 
          1 
> 
> png("cex-main.png")
> par(cex.axis=1, cex.lab=1, cex.main=2, cex.sub=1)
> main <- "par(cex.axis=1, cex.lab=1, cex.main=2, cex.sub=1)"
> plot(x, y, col=rgb(red, 0.5, 0.25, 0.8), cex=2,
+      pch=19, xlab="x-axis label", ylab="y-axis label",
+      main=main)
> title("", sub="subtitle")
> dev.off()
null device 
          1 
> 
> png("cex-sub.png")
> par(cex.axis=1, cex.lab=1, cex.main=1.2, cex.sub=2)
> main <- "par(cex.axis=1, cex.lab=1, cex.main=1.2, cex.sub=2)"
> plot(x, y, col=rgb(red, 0.5, 0.25, 0.8), cex=2,
+      pch=19, xlab="x-axis label", ylab="y-axis label",
+      main=main)
> title(sub="subtitle")
> dev.off()
null device 
          1 
The data are reproducible thanks to the set.seed function, and plots were saved to files using the png function.

Leave a Reply