Adding marker lines at specific x and y values using abline

Sometimes, we might only want to draw one or a few lines to indicate specific cutoff or threshold values. In this recipe, we will learn how to do this using the abline() function.

We will use the base graphics library for this recipe, so all you need to do is run the recipe at the R prompt. It is good practice to save your code as a script for use again later.

Let's draw a vertical line against the month of September in the rainfall graph for Tokyo:

How to do it...

To draw marker lines with abline() at specific X or Y locations, we have to set the v (as in vertical) or h (as in horizontal) arguments, respectively. In the example, we set v=9 (the index of the month September in the Month vector).

Now, let's add a red dotted horizontal line to the graph to denote a high rainfall cutoff of 150 mm:

There's more...