You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何修复R语言plot_geo报错“No scattergeo mode specifed: Setting the mode to markers”

问题原因

你触发警告的核心原因是type = "choropleth"参数放错了位置:plot_geo()默认初始化的是scattergeo类型的轨迹,你传入的type参数不会被识别,系统仍按散点地理图逻辑校验参数,才会弹出缺少scatter mode的提示。你之前添加scatter相关参数没用,是因为你要绘制的是等值面图,本身就不需要scatter模式的配置,属于修改方向错误。

修复方案

只需要调整两个位置即可:

  1. 删掉plot_geo()里的type = "choropleth"参数
  2. 在add_trace()里新增type = "choropleth"参数

修正后的完整代码如下:

athletes %>%
  rename(sport = Discipline) %>%
  group_by(country) %>%
  summarize(number_of_athletes = n()) %>%
  mutate(hover = paste0(country,"\n","Number of Athletes: ", number_of_athletes)) %>%
  plot_geo() %>%
  add_trace(type = "choropleth",
            locations = ~country, 
            locationmode = "country names", 
            z = ~number_of_athletes,
            colorscale = "Portland",
            text = ~hover, 
            hoverinfo = "text",
            marker = list(line = list(color = "gray50"))) %>%
  layout(title = list(text = "Number of Athletes by Country", font = list(size = 20), xanchor = "center", yanchor = "middle"), 
         width = 900,
         height = 500, 
         margin = list(b = 10),
         dragmode = FALSE, 
         showlegend = TRUE) %>%
  colorbar(title = "Number of Athletes") %>%
  config(displayModeBar = FALSE)

你也可以直接用plotly封装好的add_choropleth()函数替换add_trace(),省略手动指定type参数的步骤,效果完全一致。

内容的提问来源于stack exchange,提问作者Ell

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.29 22:15:02