plotly / plotly/plotly.R

Choropleth Map produces just a coloured rectangle

Aperta
#1,811 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Lingua principale
R
Stelle
2.7k
Fork
641
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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?

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia riproducendo i due trace della issue con il Natural Earth GeoJSON collegato e confronta l'output funzionante di choroplethmapbox con l'output del choropleth a colore piatto. Traccia il modo in cui il trace choropleth di R gestisce geojson, featureidkey, locations e z; il lavoro è completato quando il choropleth standard visualizza distintamente i valori dei paesi e il comportamento dell'hover per le locations mancanti è stato gestito o chiarito.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
r
Ambito
data-visualization
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.