我已经使用此链接中建议的方法复制了 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"))
指定您希望轮廓的颜色作为等值线构造图层的标记参数(原始的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"))