In this recipe, we will look at some slightly advanced code to embed histograms inside another kind of graph. We learned how to make pairs plots (a matrix of scatter plots) in Chapter 1, R Graphics, and Chapter 4, Creating Scatter Plots. In those pairs plots, the diagonal cells running from the top-left to the bottom-right showed the names of the variables, while the other cells showed the relationship between any two pairs of variables. It will be useful if we can also see the probability distribution of each variable in the same plot. Here, we will learn how to do this by adding histograms inside the diagonal cells.
We will use the inbuilt iris
flowers dataset of R. So, we need not load any other datasets. We can simply type in the given code at the R prompt.