Creating a line chart

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.

Getting ready

Once again, we recall ggplotdata for this plot. In this case, we will use the two numeric variables, which are disA and disD.

How to do it...

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:

How it works…

The single variable's connected line looks like a time series plot, ...

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

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.