Book Image

R Graphs Cookbook Second Edition

Book Image

R Graphs Cookbook Second Edition

Overview of this book

Table of Contents (22 chapters)
R Graphs Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Multiple histograms along the diagonal of a pairs plot


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.

Getting ready

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.

How to do it...

So, let's make an enhanced pairs plot showing the relationship between different measurements of the iris flower species and how each measurement's values...