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.

Getting ready

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.

How to do it...

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

rain <- read.csv("cityrain.csv") plot(rain$Tokyo,type="b",lwd=2, xaxt="n",ylim=c(0,300),col="black", xlab="Month",ylab="Rainfall (mm)", main="Monthly Rainfall in Tokyo") axis(1,at=1:length(rain$Month),labels=rain$Month) ...

Get R: Data Analysis and Visualization now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.