Three-dimensional density plots

In this recipe, we will see how we can produce a three-dimensional visualization of a bivariate density plot. The two variables will represent two axes, and the estimated density will represent the third axis, which allows us to produce a three-dimensional visualization in turn.

Getting ready

For this recipe, we will use the airquality data from the datasets library. Particularly, we will use the Ozone and Temp variables:

attach(airquality)

We are required to call the MASS library in order to use the kde2d() bivariate kernel density estimation function:

library(MASS)

How to do it...

We are aiming to estimate the bivariate kernel density estimate and then visualize it. The estimation command is as follows:

# To fill the ...

Get R: Data Analysis and Visualization now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.