Playing with Palettes

Harold Nelson

11/3/2021

Setup

library(tidyverse)
library(sf)
library(tmap)

Get Districts

sd = st_read("saep_unsd10.shp")
## Reading layer `saep_unsd10' from data source 
##   `/Users/haroldnelson/Dropbox/WA Geodata/saep_unsd10.shp' using driver `ESRI Shapefile'
## Simple feature collection with 295 features and 144 fields
## Geometry type: MULTIPOLYGON
## Dimension:     XY
## Bounding box:  xmin: 579552.7 ymin: 81835.08 xmax: 2551107 ymax: 1355593
## Projected CRS: NAD83(HARN) / Washington South (ftUS)
tm_shape(sd) + tm_borders()

Population Density

sd = sd %>% 
  mutate (density = POP2020/ALANDMI)

summary(sd$density)
##     Min.  1st Qu.   Median     Mean  3rd Qu.     Max. 
##    0.265    8.504   48.817  453.378  253.631 8918.373

Density Geography

tm_shape(sd) +
  tm_polygons(col = "density",style = "quantile") +
  tm_layout(main.title = "People/Sq. Mile \n Washington School Districts")

Playing with Palletes

Get the necessary packages and open palette_explorer()

library(tmaptools)
library(shiny)
library(shinyjs)
#palette_explorer()
Map3 = tm_shape(sd) +
  tm_polygons(col = "density",
              style = "quantile",
              palette = "YlGnBu",
              n = 3) +
  tm_layout(main.title = "People/Sq. Mile: WA School Districts \n (YlGnBu/3)")

Map5 = tm_shape(sd) +
  tm_polygons(col = "density",
              style = "quantile",
              palette = "YlGnBu",
              n = 5) +
  tm_layout(main.title = "People/Sq. Mile: WA School Districts \n (YlGnBu/5)")
tmap_arrange(Map3,Map5,ncol=2)