Fixed colorscale: chloropleth map

Hello, all. New plotly user here, and I didn’t find any past posts on this topic.

I’m trying to generate a chloropleth map with a fixed colorscale. The autocolorscale, cmin, and cmax arguments don’t appear to have any effect. Below is some sample code:

g <- list(
scope = ‘usa’,
projection = list(type = ‘albers usa’),
showlakes = TRUE,
lakecolor = toRGB(‘black’)
)
plot_ly(df, z = deviation, text = hover, locations = code, type = ‘choropleth’,
locationmode = ‘USA-states’, colorscale=colorscale, color = deviation,
autocolorscale=FALSE, cmin=-20, cmax=20,
marker = list(line = l)) %>%
layout(geo = g, margin = m, height=500)

choropleth traces use zmin and zmax to fix the colorscale bounds.

2 Likes

Thanks so much, etienne. That worked perfectly.