plotly / plotly/plotly.R

Choropleth Map produces just a coloured rectangle

Offen
#1,811 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Vorherrschende Sprache
R
Sterne
2.7k
Forks
641
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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?

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne damit, die beiden Traces im Issue mit dem verknüpften Natural Earth GeoJSON zu reproduzieren, und vergleiche die funktionierende choroplethmapbox-Ausgabe mit der Choropleth-Ausgabe in einer einzigen Farbe. Verfolge, wie der R-Choropleth-Trace geojson, featureidkey, locations und z verarbeitet; abgeschlossen ist die Arbeit, wenn die standardmäßige Choropleth die Länderwerte deutlich unterscheidbar darstellt und das Hover-Verhalten bei fehlenden Locations behandelt oder geklärt ist.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
r
Bereich
data-visualization
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
45/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.