I am using leaflet to visualize rasters. The output shows NA values around the border areas for discrete classifications. I read another post that said this might be due to the differences in projections between the raster and what leaflet uses, resulting in NA interpolated values at the edges. I tried leaflet:projectForLeafLet, but this did not change the problem.

Any ideas?

r1 <- asFactor(r)
r2 <- projectRasterForLeafLet(r1, method = 'ngb')
pal <- colorFactor(SAGA_pal[[1]], domain = c(0,10,15,20,30), ordered = FALSE,
                   na.color = "transparent", alpha = FALSE, reverse = TRUE)
(ll <- leaflet() %>% 
    addProviderTiles("Esri.WorldImagery") %>%
    addRasterImage(r2, colors=pal, opacity=0.5) %>%
    addLegend(pal=pal, values=values(r2))

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.