Changing Viridis to different color palette

195 views Asked by At

How can one change this viridis color platte as shown below to other types of viridis color palette??The code used and the map displayed below is shown for reference: enter image description here

2

There are 2 answers

0
DaveArmstrong On BEST ANSWER

The col.regions option does that. You can give it a different color palette as an argument:

library(mapview)
data(franconia)
mapview(franconia, 
        zcol = "district",  
        col.region=colorRampPalette(c("blue", "red")))

Created on 2022-06-03 by the reprex package (v2.0.1)

0
Salix On

Since the question asked specifically about the viridis color palette, code would be :

library(mapview)
data(franconia)
mapview(franconia, 
        zcol = "district",  
        col.region=viridis::viridis_pal(option = "A"))

Where you can change option="A" for "B" or "C" (the current palette used is "D"). For using the other gradients from viridis, you can use

library(mapview)
data(franconia)
mapview(franconia, 
        zcol = "district",  
        col.region=viridis::mako(n = 3))

where n must be at least as big as the number of discrete variable or bins. For your gradient, I see you have 6 values on your scale, so I'd put n at 6.