# David Zelený

Wikipages

### Sidebar

Introduction to R for Ecologists
R語言在生態學的應用
EEB5082 (B44U1940)

• Study materials • Links • Class exercise • Individual work • Homework assignments Author: David Zelený recol:parameters

# Graphical parameters

(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:

1. by calling the function `par` before the figure is actually plotted;
2. inside the high- or low-level graphical function;
3. 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:

`par ()`
```\$xlog
 FALSE

\$ylog
 FALSE

 0.5

\$ann
 TRUE

 FALSE
...```

The list of all parameters is here, details about what the parameters mean can be found in `?par` (link here)

## 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:

```par (col = 'red')
plot (dist ~ speed, data = cars)``` When the plotting function draws the figure, it will ask 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)``` ```par (old_par)
plot (dist ~ speed, cars)``` 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 `plot` function:

`plot (dist ~ speed, data = cars, pch = 21, col = 'red', bg = 'yellow')` or using the low level function:

```plot (dist ~ speed, data = cars, axes = FALSE)
axis (1, col = 'red')
axis (2, col = 'blue')``` 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 most fine 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 (make it larger, red and italics), you can wrap the relevant arguments (`cex`, `col` and `font`) into the list and assign to the argument `title`:

`plot (dist ~ speed, data = cars, main = list ('Scatterplot', cex = 4, col = 'red', font = 3))`  