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
.
Once again, we recall ggplotdata
for this plot. In this case, we will use the two numeric variables, which are disA
and disD
.
To produce a connected line of a single numeric variable against its observation index, we will use the following code:
# connected line ggplot(data=ggplotdata,aes(x=1:nrow(ggplotdata),y=disA))+geom_line()
The line chart produced is shown in the following figure:
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...