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

Creating pairs plots


A pairs plot is a matrix of scatter plots and is a very handy visualization to quickly scan the correlations between many variables in a dataset.

How to do it...

We will use the built-in iris dataset, which gives the measurements in centimeters of the sepal length and sepal width, and petal length and petal width variables, respectively, for 50 flowers from each of three species of iris:

pairs(iris[,1:4])

How it works...

As you can see in the preceding figure, the pairs() command makes a matrix of scatter plots, where all the variables in the specified dataset are plotted against each other. The variable names, displayed in the diagonal running across from the top-left corner to the bottom-right corner, are the key to reading the graph. For example, the scatter plot in the first row and second column shows the relationship between Sepal Length on the y axis and Sepal Width on the x axis.

There's more...

Here's a fun fact: we can produce the preceding graph using the plot()...