Black Lives Matter. Please consider donating to Black Girls Code today.
Dash Enterprise delivers an incredible 21x cost savings 💸Download the e-book!

How to change surface colorscale

Hi everyone,
I’m trying to change the colorscale of a surface plot, unfortunately without success.

library(plotly)
scene = list(xaxis = list(title = “d1 (bohr)”), yaxis = list(title = “d2 (bohr)”), zaxis = list(title = “DG (kcal/mol”),camera = list(eye = list (x = -1.8, y = -1.8, z = 1)))
p <- plot_ly(x=x, y=y, z=ChorismateMutaseMatrix) %>% add_surface(colorscale = “Jet”)%>%layout(title = ‘Energy profile’, scene = scene)
p

I suspect I’m passing the colorscale variable incorrectly, but I have not found how to get it right. It’s not throwing any errors, but the surface colorscale is the default red-white-blue, rather than the Jet colorscale.

Thanks in advance for your time,

Dries

You can change the color scheme using “colors” rather than “colorscale”.
E.g.

library(plotly)
scene = list(xaxis = list(title = "d1 (bohr)"), yaxis = list(title = "d2 (bohr)"), zaxis = list(title = "DG (kcal/mol"),camera = list(eye = list (x = -1.8, y = -1.8, z = 1)))
p <- plot_ly(x=x, y=y, z=ChorismateMutaseMatrix) %>% add_surface(colors = "Surface")%>%layout(title = 'Energy profile', scene = scene)
p

“Jet” is not one of the options, but you can find a range of alternatives at http://colorbrewer2.org/ (pick one and check the URI to see what the scheme is called). Perhaps “RdYlBlu” will be close enough?