13 Creating a 3D Density Plot
In order to see the KDE another way we can look at the 3D version of it using R’s capability with the “OpenGL” format, which stands for “Open Graphics Libray”. This is a web standard that enables interactive 3D in a web browser.
First we need to install the rgl
and rasterVis
packages and then load them. We also need to change an option with RStudio to allow the outputs to be displayed. The loading steps and this option change are below.
library(rgl)
library(rasterVis)
options(rgl.printRglwidget = TRUE)
Next we just use the plot3D
function to plot our density data in the form of the kde
object. Because the density values are very low it is important to multiply them by a very large number so that they can be visible on the scale that the map is plotted at.
plot3D(kde, zfac=10000000)