Different color palette for NDVI image on Leaflet map

Hello,

I believe this issue could be because the way you use Leaflet doesn’t support RGB.

To get around this you can use a package called leafem. Your code would look something like this.

# Load image as a brick (https://www.rdocumentation.org/packages/raster/versions/3.4-13/topics/brick)
r <- brick("~/response_JPEG.png") 

val <- c(19.06162, 19.34916, -34.45179, -34.31693)
crs(r) <- "+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0"
im <- raster::setExtent(r ,val) 

# addRasterRGB comes from the leafem library
leaflet() %>% addTiles() %>% addRasterRGB(im)

Let me know if you’d need any further help!

Best regards,
Pontus

1 Like