# 3d contour plot in R

I have 2 vectors $1000 \times 1$, lets call them $y_{1}$ and $y_{2}$. Each vector represents a normal distribution with certain mean and variance.

I plot the contour plot using the following R code:

x <- y1
y <- y2
s <- subplot(
plot_ly(x = x, type = "histogram", showlegend=FALSE),
plotly_empty(),
plot_ly(x = x, y = y, type = "histogram2dcontour", showlegend=FALSE),
plot_ly(y = y, type = "histogram", showlegend=FALSE),
nrows = 2, heights = c(0.2, 0.8), widths = c(0.8, 0.2),
shareX = TRUE, shareY = TRUE, titleX = FALSE, titleY = FALSE
)
layout(s)


and i get the following plot

What I would like to do now, is to plot a 3D contour plot (so that I can actually see the "mountain" that is created after plotting the histogram of $y_{1}$ against the histogram of $y_{2}$). So in the z-axis I would like to have the frequencies of the values. Any suggestions ?

• Please make a reproducible example that we can cut and paste and run. Also, state which packages you are using, because this looks like you are using a "plotly" package of some sort. Also also, try posting to stackoverflow unless you have a real data science question. Jul 18, 2016 at 13:07

freqz <- with(data.frame(x,y), MASS::kde2d(x, y, n = 50))