qfes / rdeck

Deck.gl widget for R
https://qfes.github.io/rdeck
MIT License
97 stars 0 forks source link

Unclear how to use get_fill_color with a scale referring to an MVT data field #53

Closed dwachsmuth closed 2 years ago

dwachsmuth commented 2 years ago

Apologies if I'm missing something obvious, but I can't figure out how to set the fill colour of an MVT layer with a scale referencing a data field in the MVT source.

I've got:

rdeck(initial_view_state = view_state(center =  c(-73.58, 45.53), zoom = 9)) |> 
  add_mvt_layer(data = mvt_url("dwachsmuth.borough_5"),
                get_fill_color = scale_color_linear(
                  col = "canale_ind_2016",
                  palette = c("#FF00FF", "#00FF00"),
                  limits = c(0, 5)))

Which I hope would scale the fill colour with reference to the "canale_ind_2016" field present in my MVT data source, but instead all polygons are filled with the fallback colour (black).

Is there some way to accomplish this?

anthonynorth commented 2 years ago

Your reprex looks ok, so I assume that the problem is data.

The default colour for NA is black, so this suggests that the field doesn't exist, is not numeric, or all values are null / nan. You can easily verify this by making the layer pickable and adding a tooltip.

Example using country boundaries:

rdeck() |>
  add_mvt_layer(
    data = mvt_url("mapbox.country-boundaries-v1"),
    get_fill_color = scale_color_linear(
      col = color_group,
      palette = viridis::viridis(6),
      limits = c(1, 6)
    ),
    auto_highlight = TRUE,
    pickable = TRUE,
    tooltip = TRUE
  )

image

anthonynorth commented 2 years ago

You might also try looking at the tile json, which you can access via: https://api.mapbox.com/v4/dwachsmuth.borough_5.json?access_token=<your token>

dwachsmuth commented 2 years ago

Arrgh, sorry, you're right—I had a misnamed field. Many apologies for not triple-checking that ahead of time!

(I had previously tried to make it pickable to do this exact verification, but that didn't work either, presumably because I had misnamed the field....)