Skip to content

disarm-platform/MapPalettes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

83 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MapPalettes

A set of nifty palettes and functions for maps designed by the DiSARM team at UCSF

Install

library(devtools)  
install_github("disarm-platform/MapPalettes")
library(MapPalettes)

Palettes

Examples

view_palette("green_machine", n=64, type = "raster") 

To create a hex bin plot from a raster

library(leaflet) # for colorNumeric function
data("swz_elev")
hexbins <- hexbin_raster(swz_elev, n=300, function(x) mean(x, na.rm = TRUE))
col_pal <- colorNumeric(map_palette("bruiser", n=10), hexbins$stat)
plot(hexbins, col = col_pal(hexbins$stat))

To create a hex bin plot from points and plot using leaflet

This example uses the supplied Demographic and Health Survey data on BCG vaccination in the DRC

library(leaflet) 

# Load data
data("BCG_vaccination_DRC")

# Generate hexbins
hexbins <- hexbin_points(BCG_vaccination_DRC, n = 400, fun = mean, z = "coverage")

# Generate color palette
col_pal <- colorNumeric(rev(map_palette("tealberry_pie", n=10)), hexbins$stat)

# Plot
leaflet() %>% addProviderTiles("CartoDB.DarkMatter") %>%
          addPolygons(data = hexbins, col = col_pal(hexbins$coverage),
          fillOpacity = 0.7) %>%
          addLegend(pal = col_pal, values = hexbins$coverage, 
          title = "Coverage")

To get main color groups from an image (Photo by Nathan Lindahl on Unsplash.com)

get_colors_from_image("https://raw.githubusercontent.com/HughSt/mappalettes/master/images/nathan-lindahl-1j18807_ul0-unsplash.jpg",5)
[1] "#0C080B" "#142D40" "#425662" "#B3330C" "#F8A14B"

About

A set of mapping and color palette functions

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages