plotly / plotly/plotly.R

Choropleth Map produces just a coloured rectangle

未关闭
#1,811 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

主要语言
R
星标
2.7k
派生
641
PR 合并指标
30 天内没有已合并 PR

描述

I am trying to draw a Plotly choropleth map using a custom geojson created using the Natural Earth 10m map-unit dataset. (I need Wales/Scotland/Ireland/England etc).

If I plot with mapbox I get the expected output (although my polygons don't quite fit the background) however if I try to just use choropleth I get a square of just one colour (I can still see hover values though).

A subset of my data for USSR countries:

    library(data.table)
    library(plotly)
    countries <- rjson::fromJSON(file="https://raw.githubusercontent.com/awgymer/map-data/master/ne_10m_admin_0_map_units.json")

    first_gms <- fread(
    "team_name,geounit,played_for
    USSR,BLR,14671
    USSR,TJK,6516
    USSR,UZB,12484
    USSR,MDA,7007
    USSR,UKR,739
    USSR,KAB,7182
    USSR,LVA,6559
    USSR,KAZ,7182
    USSR,ARM,10895
    USSR,RUS,6516
    USSR,AZE,11213
    USSR,KGZ,12481
    USSR,GEA,5518
    USSR,EST,14671
    USSR,TKM,6516
    USSR,GEG,5518
    USSR,LTU,6845")
    
    fig <-  plot_ly(first_gms) %>% add_trace(
      type="choroplethmapbox",
      geojson=boundaries,
      featureidkey="properties.GU_A3",
      z=~played_for,
      locations=~geounit,
      colorscale="Viridis",
      marker=list(line=list(
        width=0)
      )
    ) %>% layout(
      mapbox=list(
        style="carto-positron"
      )
    )
    
    
    fig2 <-  plot_ly(first_gms) %>% add_trace(
      type="choropleth",
      geojson=boundaries,
      featureidkey="properties.GU_A3",
      z=~played_for,
      locations=~geounit,
      colorscale="Viridis",
      marker=list(line=list(
        width=0)
      )
    ) %>% layout(
      geo = list(resolution=50)
    )

fig works but fig2 is just all one colour. I cannot for the life of me work out the reason!

As an addendum: Is there any way to specify hover for countries which have no value in z/locations?

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先,使用链接的 Natural Earth GeoJSON 重现 issue 中的两个 trace,并比较正常工作的 choroplethmapbox 输出与纯色 choropleth 输出。跟踪 R choropleth trace 如何处理 geojson、featureidkey、locations 和 z;完成的标准是标准 choropleth 能够清晰地区分显示各国的值,并且缺失 location 时的 hover 行为已得到处理或说明。

由索引模型根据 Issue 内容生成。

评估

技术栈
r
领域
data-visualization
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
45/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。