Chapter 7. Creating Histograms

In this chapter, we will cover the following recipes:

  • Visualizing distributions as count frequencies or probability densities
  • Setting bin size and the number of breaks
  • Adjusting histogram styles – bar colors, borders, and axes
  • Overlaying a 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 at histograms in detail. They are a very useful form of visualization for rapidly viewing 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 (the frequency or probability of values) and also how the values are grouped into bins. We will also look at the usual parameters to change 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
3.144.14.150