## A simple 3D histogram

We have studied histograms in Chapter 1, *A Simple Guide to R*. We will try to plot a 3D histogram in this recipe. The applications of 3D histograms are limited, but they are a great tool for displaying multiple variables in a plot. In order to construct a 3D histogram, as shown in the following screenshot, we will use the `plot3d`

package available in R.

### Getting ready

To plot a histogram in 3D, we will use the `plot3D`

package available in R.

### How to do it…

We will install as well as load the `plot3D`

package in R using the `install.packages()`

and `library()`

functions, respectively.

install.packages("plot3D") library(plot3D)

We will now generate data for the *x* and *y* values using the `seq()`

function:

x = y = seq(-4,4,by =0.5 )

The 3D histogram requires the *z* variable as well, which is generated using our function `f`

defined using the following line of code:

f = function(x,y){z = (25-(x^2-y^2))}

The *z* values are generated using the `outer()`

function, which consists of the *x* and *y* values as...