cmirian
cmirian

Reputation: 2253

How to manually change diverging colors in leaflet map/R?

I have produced a map of Denmark

library(leaflet.extras)
library(leaflet)

#Data

folk1 <- readr::read_csv2("http://api.statbank.dk/v1/data/folk1a/CSV?OMR%C3%85DE=*")


municipalityDK("INDHOLD","OMRÅDE",data=folk1,legend=T,pal = "GnBu") %>%
  setMapWidgetStyle(list(background= "white"))

Which looks like:

enter image description here

However, I have not succeeded in finding a color palette that visualizes data the way I prefer. I have used those listed here.

I would like the color palette to look like this:

enter image description here

Can this be done manually?

Upvotes: 2

Views: 568

Answers (1)

Ben
Ben

Reputation: 30539

You can create a custom palette with RColorBrewer:

library(RColorBrewer)

colfunc <- colorRampPalette(c("#2C77BF", "red"))

Then include your custom palette and number of selected colors in your map:

municipalityDK("INDHOLD","OMRÅDE",data=folk1,legend=T,pal = colfunc(10)) %>%
  setMapWidgetStyle(list(background= "white"))

Map

map

Upvotes: 3

Related Questions