r-spatial / leafem

leaflet extensions for mapview
https://r-spatial.github.io/leafem/
Other
108 stars 30 forks source link

When using addGeoRaster viridis color palette, how do you create a matching legend? #55

Closed jzadra closed 2 years ago

jzadra commented 2 years ago

Following the example in #25 where viridisLite::inferno is used in the colorOptions, what is the best way to add a legend with that palette?

I've tried:

pal <- colorNumeric(viridisLite::inferno, domain = values(myraster),
                    na.color = "transparent")
 addLegend(pal = pal, values = values(myraster))

as well as

 addLegend(pal = viridisLite::inferno, values = values(myraster))

And neither work.

tim-salabim commented 2 years ago

Hi, I think you need to explicitly set how many colors you want to generate. This works for me:

pal = colorNumeric(
  viridisLite::inferno(256)
  , domain = tst[[1]]
  , na.color = "transparent"
)
jzadra commented 2 years ago

Works for me too! Thanks.