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 three-dimensional scatter plots


In this recipe, we will learn how to create three-dimensional scatter plots that can be very useful when we want to explore the relationships between more than two variables at a time.

Getting ready

We need to install and load the scatterplot3d package in order to run this recipe:

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

How to do it...

Let's create the simplest default three-dimensional-scatter plot with our mtcars dataset:

scatterplot3d(x=mtcars$wt,
              y=mtcars$disp,
              z=mtcars$mpg)

How it works...

That was easy! The scatterplot3d() functions much like the basic plot() function. In the preceding example, all we had to provide was wt, disp, and mpg from the mtcars dataset as the x, y, and z arguments, respectively.

There's more...

Just like plot() and other graph functions, scatterplot3d() accepts a number of additional arguments using which we can configure the graph in many ways. Let's try some of these additional settings...