I am trying to make a 3 Dimensional Graph between variables "x, y and w", and color this graph according to values of "z" :

```
library(plotly)
library(dplyr)
X <- seq(0,3.1,0.1)
Y <- seq(0,3.1,0.1)
W <- seq(0,3.1,0.1)
DF <- expand.grid(X,Y, W)
#Compute variable for colors
DF$Z <- sin(DF$Var1) + cos(DF$Var2) + sin(DF$Var3)
#make a matrix of color values
Mat <- matrix(DF$Z,nrow = 32)
#make a matrix for z values
#had real data.
Mat2 <- matrix(rep(c(1:16,16:1),32),nrow=32)
plot_ly(y=~Y,x=X, z=~W) %>%
add_surface(surfacecolor=~Mat)
```

But this produces an error:

```
Error: `z` must be a numeric matrix
```

Can anyone please show me how to fix this problem?

Thanks