Chapter 3. Creating Scatter Plots

In this chapter, we will cover:

  • Grouping data points within a scatter plot
  • Highlighting grouped data points by size and symbol type
  • Labelling data points
  • Correlation matrix using pairs plot
  • Adding error bars
  • Using jitter to distinguish closely packed data points
  • Adding linear model lines
  • Adding non-linear model curves
  • Adding non-parametric model curves with lowess
  • Making three-dimensional scatter plots
  • Making Quantile-Quantile plots
  • Displaying data density on axes
  • Making scatter plots with smoothed density representation

Introduction

In this chapter, we will learn about scatter plots in depth by looking at some advanced recipes. Scatter plots are one of the most commonly used type of graphs in data analysis. In the first chapter we learnt how to make a basic scatter plot. Now we will see how we can make more enhanced plots by adjusting various arguments and using some new functions.

So far, we have mostly only used the base graphics functions such as plot(), but in this chapter we have recipes that use other graph libraries such as lattice and ggplot2, which offer more advanced control over graphs. It is possible to make these advanced graphs using the base library too, but the additional libraries give us ways to achieve the same results with less code and often produce better looking graphs with the least amount of effort.

A lot of new functions will be introduced in this chapter. It is good practice to look up the help file whenever you encounter a new function. For example, to look up the help file for the plot() function, you can type ?plot or help(plot) at the R command prompt.

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