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

Three-dimensional scatter plots


A scatter plot is one of the simplest plots that help us view the relationship between two numeric variables. In this recipe, we will see how we can produce the scatter plot from three variables with a 3D plot. A 3D plot is good way to visualize the pattern of relation among three variables at a time. Sometimes, it could happen that a 3D plot is not depicting the relation pattern in a good shape; in this case, we might rotate the plot to find out the correct pattern. However, in this recipe, we will create a simple 3D scatter plot using three continuous variables.

Getting ready

To produce a three-dimensional scatter plot, we need to load the scatterplot3d library. If it is not already installed, then we can install it using the following command:

# To install scatterplot3d library
install.packages("scatterplot3d")

# Loading the library
library(scatterplot3d)

We will use the airquality dataset for this recipe.

How to do it…

The primary command to produce a three...