Truong Nhat Minh
Truong Nhat Minh

Reputation: 207

Plot_ly color not corresponding to z

I am trying to plot a 3d graph by using plot_ly

x = c(1:5)
y = c(1:5)
z = matrix(c(1:20),nrow=5)
z_col = matrix(c(31:50),nrow=5)
plot_ly(x = ~ x, y = ~ y, z= ~ z) %>% add_surface()

The color of the surface will depend on z value. However, I want that color to depend on an external variable (z_col). I have tried to add in the color manually, but it doesn't work:

plot_ly(x = ~ x, y = ~ y, z= ~ z, color = ~ z_col) %>% add_surface()

Is there any way for me to do it ?

Upvotes: 0

Views: 92

Answers (1)

Marco Sandri
Marco Sandri

Reputation: 24262

Use surfacecolor instead of color:

plot_ly(x = ~ x, y = ~ y, z= ~ z, surfacecolor = ~ z_col) %>% add_surface()

enter image description here

Upvotes: 1

Related Questions