Line charts are sometimes useful in order to view the pattern of a single variable against its index. Also, in some cases, bivariate connected lines are also useful. In this recipe, we will draw a line chart using ggplot2
with geom_line
.
The single variable's connected line looks like a time series plot, but the difference is that this plot does not have the time axis. The x
argument within aes()
specifies the values of the x-axis. In this case, the value of x-axis is just the sequence number starting from 1
to the number of observations in the dataset. So, the aes()
function internally produces coordinates in the x-y plane with x
with the index value and y
, takes the value from the disA
variable, and then connects the points in order to produce the line.
To display the data points along with a connected line, we can use the following code: