Chapter 6. Creating Histograms

In this chapter, we will cover:

  • Visualizing distributions as count frequencies or probability densities
  • Setting bin size and number of breaks
  • Adjusting histogram styles: bar colors, borders, and axes
  • Overlaying density line over a histogram
  • Multiple histograms along the diagonal of a pairs plot
  • Histograms in the margins of line and scatter plots

Introduction

In this chapter, we will look in some detail at histograms, which are a very useful form of visualization to quickly see the distribution of values of a variable. They are usually one of the first graphs looked at to see whether a variable follows a normal distribution or has a skewed distribution.

We will see how we can enhance the basic histogram in R by adjusting some parameters in the base graphics library. We will learn how to change certain settings to control the format in which the histogram is plotted (frequency or probability of values) and also how the values are grouped into bins. We will also look at the usual parameters for changing the styling of histogram bars, such as color, width, and border. In addition, we will also look at some advanced recipes combining histograms with other types of graphs.

As with the previous chapters, it is best to try out each recipe first with the example shown here and then with your own datasets so that you can fully understand each line of code.

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

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