R Tutorial: Optional arguments

Learn how to customize R plots with optional arguments. Add titles and axis labels with `main` and `xlab`, control histogram bins with `nint`, add grid lines to scatter plots, and draw reference lines with `abline`.
Chapters
Xyplot and Histogram are high level functions in the sense that they provide the direct user interface for creating plots. There are more high level functions that you will soon encounter. All these high level functions have two mandatory arguments. The first argument is the formula X and the second argument is data, which is a data set containing variables mentioned in the formula. There can also be one or more optional arguments that modify the visualization in some way. Some of these arguments are applicable to all functions and some have their effects specific to particular functions. Let's look at some examples. Here's an update of our previous histogram that adds a title and a descriptive label for the x axis. These are things you will definitely want to add in a presentation plot. These are done using the main and XLAB arguments, which should both be character strings. Here is a similar update for our scatterplot. Some arguments are specific to the type of display being created. For example, the nint argument in Histogram, which stands for the number of intervals, is used to specify the number of bins to be used. Similarly, the grid and abline arguments are specific to xyplot. The argument grid true adds a background reference grid. The abline argument is used to add one or more reference lines. Here the vector 0 comma 1 represents a line with intercept 0 and slope 1, or in other words, the y equals x diagonal line. You will learn about some more useful optional arguments in the following exercises.
More from Richie

#359 My Best Friend is AI with Valerie Tiberius, Professor of Philosophy at University of Minnesota

How AI Agents Will Work While You Sleep | Ruslan Salakhutdinov, Professor at Carnegie Mellon

#358 How AI Agents Will Work While You Sleep | Ruslan Salakhutdinov, Professor at Carnegie Mellon







