I'd like to overlay a scatter plot on my 3D density graph using the plotly package and the add_trace function. I used this code :
den3d <- kde2d(data_loc$X, data_loc$Y)
persp(den3d, box=FALSE)
plot_ly(x=den3d$x, y=den3d$y, z=den3d$z, type="surface") %>%
add_trace(x=data_loc$X,y=data_loc$Y,mode="markers", type="scatter")%>%
layout(
scene=list(
xaxis=list(title='X Axis (m)'),
yaxis=list(title='Y Axis (m)'),
zaxis=list(title='Probability density')
))
to make this plot : 3D density plot and scatter plot
But I'd like my scatter plot to use the same x and y axes as the 3D density diagram. What I have in mind might look like this: The plot i want
I also tried to add the scatter plot using the ggplot package but without succes.