- R Graphs Cookbook Second Edition
- Jaynal Abedin Hrishi V. Mittal
- 287字
- 2021-08-05 17:30:29
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()
function instead of pairs()
in exactly the same manner:
plot(iris[,1:4], main="Relationships between characteristics of iris flowers", pch=19, col="blue", cex=0.9)

So, if you pass a data frame with more than two variables to the plot()
function, it creates a scatter plot matrix by default. We've also added a plot title and modified the plotting symbol style, color, and size using the pch
, col
, and cex
arguments, respectively. We delve into the details of these settings in Chapter 3, Beyond the Basics – Adjusting Key Parameters.
See also
We cover some more interesting recipes in Chapter 4, Creating Scatter Plots, building upon the things you learned in Chapter 3, Beyond the Basics – Adjusting Key Parameters.
- 圖解西門子S7-200系列PLC入門
- Learning Cocos2d-x Game Development
- Raspberry Pi 3 Cookbook for Python Programmers
- Cortex-M3 + μC/OS-II嵌入式系統開發入門與應用
- 電腦維護與故障排除傻瓜書(Windows 10適用)
- SDL Game Development
- 基于ARM的嵌入式系統和物聯網開發
- Manage Partitions with GParted How-to
- Artificial Intelligence Business:How you can profit from AI
- 微服務分布式架構基礎與實戰:基于Spring Boot + Spring Cloud
- Visual Media Processing Using Matlab Beginner's Guide
- Python Machine Learning Blueprints
- FL Studio Cookbook
- 單片機原理及應用
- Blender 3D By Example