R Tutorial: Optional arguments

Published: 27 February 2020
on channel: DataCamp
395
1

Want to learn more? Take the full course at https://learn.datacamp.com/courses/da... at your own pace. More than a video, you'll learn hands-on coding & quickly apply skills to your daily work.

---

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'll soon encounter.

All these high-level functions have two mandatory arguments. The first argument is formula x, and the second argument is data, which is a dataset 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 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'll 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 scatter plot.

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 equals 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'll learn about some more useful optional arguments in the following exercises.


On this page of the site you can watch the video online R Tutorial: Optional arguments with a duration of hours minute second in good quality, which was uploaded by the user DataCamp 27 February 2020, share the link with friends and acquaintances, this video has already been watched 395 times on youtube and it was liked by 1 viewers. Enjoy your viewing!