如何更改 R Plotly choropleth 地图中的州边界颜色?

问题描述 投票:0回答:1

我已经使用此链接中建议的方法复制了 R 中离散颜色的等值线图:如何根据分类变量在 R Plotly 中创建叶绿体图?

但是,您会注意到,图中的州线/边界是蓝色的。我希望它是黑色的,这样情节就更清晰了。

我尝试了下面的代码,但它似乎不起作用。

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")) 
r plotly maps categorical-data
1个回答
0
投票

指定您希望轮廓的颜色作为等值线构造图层的标记参数(原始的plot_ly调用或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

© www.soinside.com 2019 - 2024. All rights reserved.