0

I have replicated the choropleth map for discrete colors in R using the method suggested in this link: How to create a chloropleth map in R Plotly based on a Categorical variable?

However, as you will notice, the state lines / boundaries in the plot is blue. I'd like this to be black so that the plot is clearer.

I tried the following code below but it doesn't seem to work.

cw_map <- plot_ly(
  data = df,
  type = "choropleth",
  locations = ~ state,
  locationmode = "USA-states",
  z = df$test,
  colorscale=colorScale,
  colorbar=list(tickvals=1:nfactor, ticktext=names(foo))
) %>%
layout(geo = list(scope = "usa", showsubunits = TRUE, subunitcolor = "black")) 
3
  • line = list(color = 'black')? Commented Jul 22, 2024 at 22:01
  • @Dubukay Doesn't seem to work - do you add this to the layout? Commented Jul 22, 2024 at 23:05
  • plotly.com/r/map-configuration/… Commented Jul 23, 2024 at 1:16

1 Answer 1

1

Specify the color you'd like the outline to be as a marker argument to the choropleth construction layer (either the original plot_ly call or the add_trace):

cw_map <- plot_ly(
  data = df,
  type = "choropleth",
  locations = ~ state,
  locationmode = "USA-states",
  z = df$test,
  colorscale=colorScale,
  colorbar=list(tickvals=1:nfactor, ticktext=names(foo)),
  marker = list(line=list(color = 'black'))
) %>%
  layout(geo = list(scope = "usa", showsubunits = TRUE, subunitcolor = "black"))

screenshot of plotly map with black outlines instead of blue

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.