riatelab / cartography

Thematic Cartography for R
http://riatelab.github.io/cartography/docs/
398 stars 46 forks source link

using 'custom' colors? #53

Closed jeffcsauer closed 5 years ago

jeffcsauer commented 5 years ago

Hello again!

Quick question! Is it possible to use custom color gradients?

For example, is it possible to set the lowest value as "white" and highest value as "dodgerblue4"?

I saw the post about using hex colors but did not have luck...

rCarto commented 5 years ago

This is not particularly related to cartography, which uses whatever colors you give it. Anyway, I would probably use colorRampPalette().

library(cartography)
library(sf)
#> Linking to GEOS 3.5.1, GDAL 2.2.3, PROJ 4.9.3
mtq <- st_read(system.file("gpkg/mtq.gpkg", package="cartography"), quiet = T)

cols <- colorRampPalette(colors = c("white", "dodgerblue4"))(6)

choroLayer(x = mtq, var = "MED", nclass=6, method = "quantile", col = cols)