Chapter 5. Creating Line Graphs and Time Series Charts

In this chapter, we will cover the following recipes:

In Chapter 1, R Graphics, and Chapter 3, Beyond the Basics – Adjusting Key Parameters, we learned some basics of how to make line graphs and customize them by setting certain arguments as per our needs. In this chapter, we will learn some intermediate to advanced recipes to customize line graphs even further. We will look at ways to improve and speed up line graphs with multiple lines that represent more than one variable.

One of the most used forms of line graphs is time trends or time series, where the X variable is some measure of time such as year, month, week, day, hour, and so on. Reading, formatting, and plotting dates can be quite tricky in R. In this chapter, we will see how to deal with dates and process them to make time series charts with custom annotations, grid lines, uncertainty bounds, and markers.

We will also learn to make some interesting and popular types of time series charts such as sparklines and stock charts.

As the recipes in this chapter are slightly more advanced than the earlier chapters, it might take some practice with multiple datasets before you are comfortable with using all the functions. Example datasets are used in each recipe, but it is highly recommended you also work with your own datasets and modify the recipes to suit your own analysis.