Home > Back-end >  Changing Viridis to different color palette
Changing Viridis to different color palette

Time:06-04

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

CodePudding user response:

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)

CodePudding user response:

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.

CodePudding user response:

mapview::mapView() seems to have some arguments you could use.

Something like mapView(x, zcol = NULL, color = mapviewGetOption("vector.palette"), col.regions = mapviewGetOption("vector.palette"))

  • Related