Table of Contents
(The R code used for this website is here)
The basic graphics in R is very flexible in what all can be modified. The graphical parameters can be modified on several levels:
- by calling the function
parbefore the figure is actually plotted;
- inside the high- or low-level graphical function;
- by wrapping parameters into the list together with the argument of the plotting function.
If you call the function
par () (with emtpy parenthesis), it will return the list of all graphical parameters with their default setting:
$xlog  FALSE $ylog  FALSE $adj  0.5 $ann  TRUE $ask  FALSE ...
1. Using par () function
Most of the parameters can be changed inside the
par function. The difference from changing these parameters e.g. in the
plot function is that the change is persistent - it will apply to all figures plotted in that graphical device, unless you change the value again or close the device. The function
par needs to be called before the figure is actually plotted. For example, if you want to change the colour in which items in the figure are plotted, you can do it by calling
par function with given argument, and then by plotting the figure:
When the plotting function draws the figure, it will check the current setting of the graphical parameters to know which values to use; if we change it (as in this case for the parameters
col), it will use this value to plot the figure.
One way to make sure that you can set the parameters to the state before change is to store the initial value when you change them:
old_par <- par (mfrow = c(1,2), col = 'red', bg = 'grey') plot (dist ~ speed, cars) plot (Volume ~ Girth, trees)
Parameters which can be modified only by calling the
par function are listed in the following table (from R Graphics by P. Murrel):
2. Modify the argument inside the high- or low-level graphical function
You can modify the values of these parameters when you plot the figure itself, e.g. using the
or using the low level function:
The list of parameters that can be used in this way is here:
3. Wrapping parameters into the list together with the argument of the plotting function
This is the finest control of the graphical parameters. You can wrap them together with the value of the argument when you call the argument inside the high- or low-level graphical function.
For example, if you want to change the appearance of the main text plotted above the scatterplot (making it larger, red and italics), you can wrap the relevant arguments (
font) into the list and assign to the argument