Reputation: 146
I have created a heatmap on top of a city that I would like to color from red to green depending on density. if I leave color as 'red' or 'blue' it will create a color scale of that one color. Yet I cannot seem to figure out how to do a green to red.
I have tried both what I have here and also a palette option that doesn't seem to get anywhere. This current one shows up black.
Does anyone know how to get these colors to show?
leaflet() %>%
addProviderTiles("OpenStreetMap.BlackAndWhite",
options = providerTileOptions(noWrap = TRUE,minZoom=9)) %>%
addPolygons(data=polys_dat,color= ~rainbow(n=50,start=0,end=.3), stroke = FALSE) %>%
setMaxBounds(-0.715485, 51.252031, 0.514984, 51.745313) %>%
setView(.1,51.5, zoom = 9)
Upvotes: 0
Views: 2540
Reputation: 366
You need to create the palette function first and then use that in your addPolygons
function. If we assume you have a field in your polys_dat
function called density
with your values then the following should work.
pal = colorNumeric(colorRamp(c('green', 'red')), polys_dat$density)
leaflet() %>%
addProviderTiles("OpenStreetMap.BlackAndWhite",
options = providerTileOptions(noWrap = TRUE,minZoom=9)) %>%
addPolygons(data=polys_dat,color= ~pal(density), stroke = FALSE) %>%
setMaxBounds(-0.715485, 51.252031, 0.514984, 51.745313) %>%
setView(.1,51.5, zoom = 9)
Upvotes: 3