9.1 3-D Scatterplot

  • Since the ggplot2 package and its extensions can’t create a 3-D plot, you can create a 3-D scatterplot with the scatterplot3d function in the scatterplot3d package.

  • Let’s plot automobile mileage vs. engine displacement vs. car weight using the data in the mtcars dataframe – mtcars comes with base R and contains information on 32 cars measured on 11 variables.

library(scatterplot3d)
with(mtcars, {
   scatterplot3d(x = disp,
                 y = wt, 
                 z = mpg,
                 main = "3-D Scatterplot Example 1")
})