Chapter 4. Creating Line Graphs and Time Series Charts

In this chapter, we will cover:

  • 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
  • Creating sparklines
  • Plotting functions of a variable in a dataset
  • Formatting time series data for plotting
  • Plotting date and time 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, Basic Graph Functions and Chapter 2, Beyond the Basics: Adjusting Key Parameters, we learnt 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 more intermediate to advanced recipes for customizing line graphs even further. We will look at ways to improve and speed up line graphs with multiple lines representing more than one variable.

One of the most used form 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 may 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 to 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