I am using the R programming language. I am following this tutorial over here for making 3d kernel density plots in R: https://plotly.com/r/3d-surface-plots/:
library(MASS)
library(plotly)
kd <- with(MASS::geyser, MASS::kde2d(duration, waiting, n = 50))
fig <- plot_ly(x = kd$x, y = kd$y, z = kd$z) %>% add_surface()
fig
I decided to try this on my own data :
#generate data
a = rnorm(100,10,10)
b = rnorm(100,5,5)
c = rnorm(100,5,10)
d = data.frame(a,b,c)
#make 3d plot (I think n = 50 refers to selecting the first 50 points?)
kd <- with(d, MASS::kde2d(a,b,c, n = 50))
fig <- plot_ly(x = kd$x, y = kd$y, z = kd$z) %>% add_surface()
But this results in the following error:
Error in MASS::kde2d(a, b, c, n = 50) :
bandwidths must be strictly positive
This error prevents me from creating the "kd" object.
Can someone please tell me what am I doing wrong? Is there a problem with the specific data I am using? Or is this a syntax error?
Thanks