'R not changing Plotly colorscales for Contour plots

Okay, so I am using a generic data set to troubleshoot this problem. Here is the code I am entering into R:

library(plotly)

fig <- plot_ly(
  type = 'contour',
  z = matrix(c(10, 10.625, 12.5, 15.625, 20, 5.625, 6.25, 8.125, 
               11.25, 15.625, 2.5, 3.125, 5, 8.125, 12.5, 0.625, 
               1.25, 3.125, 6.25, 10.625, 0, 0.625, 2.5, 5.625, 
               10), nrow=5, ncol=5),
  colorscale = 'plasma',
  autocontour = F,
  contours = list(
    start = 0,
    end = 8,
    size = 2
  )
)

fig

As you can see, I have the colorscale argument set to plasma, which is a built-in colorscale according to plotly ( https://plotly.com/python/builtin-colorscales/ )

However, when I actually execute the code, the resulting graph is NOT in plasma colorscale, which goes from purple to red to yellow.

enter image description here

But when I set the colorscale = 'Jet', the resulting graph is in jet colorscale. enter image description here

How do I fix this? I want to be able to quickly change the colorscale to any of the built-in ones, so I can see which one my plot looks best in. I also don't want to have to manually define the color for each level of the plot.

Furthermore, when going to the colorscale page for R, the section on contour plots doesn't specify the colorscale variable at all.

https://plotly.com/r/colorscales/

Maybe I am missing something in the https://plotly.com/r/contour-plots/ page, but I can't find code that integrates defined start and stop points and built-in colorscale besides the one shown above.



Solution 1:[1]

Your issue is that the color scale 'plasma' is available for the python version of plotly, but not for the R version

According to the R documentation, you can check the supported color scales in R with:

library("RColorBrewer")
brewer.pal.info

BrBG PiYG PRGn PuOr RdBu RdGy RdYlBu RdYlGn Spectral Accent Dark2 Paired Pastel1 Pastel2 Set1 Set2 Set3 Blues BuGn BuPu GnBu Greens Greys Oranges OrRd PuBu PuBuGn PuRd Purples RdPu Reds YlGn YlGnBu YlOrBr YlOrRd

Specifically for contour plots the supported scales:

Blackbody,Bluered,Blues,Cividis,Earth,Electric,Greens,Greys,Hot,Jet,Picnic,Portland,Rainbow,RdBu,Reds,Viridis,YlGnBu,YlOrRd.

The strings are case-sensitive, so colorscale = "Viridis" will work, but colorscale = "viridis" won't.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Gorka