Chapter 5. Creating Line Graphs and Time Series Charts

In this chapter, we will cover the following recipes:

  • Adding customized legends for multiple-line graphs
  • Using margin labels instead of legends for multiple-line graphs
  • Adding horizontal and vertical grid lines
  • Adding marker lines at specific X and Y values using abline
  • Creating sparklines
  • Plotting functions of a variable in a dataset
  • Formatting time series data for plotting
  • Plotting the date or time variable on the X axis
  • Annotating axis labels in different human-readable time formats
  • Adding vertical markers to indicate specific time events
  • Plotting data with varying time averaging periods
  • Creating stock charts

Introduction

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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.64.192