Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
dwachsmuth opened this issue Mar 13, 2022 · 3 comments

Comments

@dwachsmuth
Copy link

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
Copy link
Member

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
Copy link
Member

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
Copy link
Author

dwachsmuth commented Mar 13, 2022

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....)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants