Black Lives Matter. Please consider donating to Black Girls Code today.

Color Choropleth Maps By Category

Hi All. I want to color US map by 3 different categories. What I did is create a column shows the category of each state and set it as Z value to create the map. However, in this case, legend cannot show correctly.

Can someone give me a hint to color map by categories or fix this legend problem? Thanks ahead.

sample = read.csv('sample.csv')
g <- list(
  scope = 'usa',
  projection = list(type = 'albers usa'),
  showlakes = TRUE,
  lakecolor = toRGB('white')

colorscale = c("#f7fbff","#85bcdb","#08519c")
p <- plot_geo(sample, locationmode = 'USA-states') %>%
  add_trace(z = ~Category_Color, text = ~FIPS, locations = ~Postal_Code,color = ~Category_Color,colors = colorscale,showscale = T,showlegend = T) %>%
  add_text(x = ~Longitude, y = ~Latitude, text = ~Postal_Code,showlegend = F)%>%
  layout(title = Sample',geo = g)
p %>% offline()