This demonstrates an alternative to the choropleth for showing the median income of counties in the State of Washington. Instead of coloring the land mass of a county, median income is mapped to the color of a dot placed at the centroid of each county. The size of the dot is used to describe the population of each county. This avoids the use of land area as an indicator of importance.
library(openintro)
## Please visit openintro.org for free statistics materials
##
## Attaching package: 'openintro'
## The following objects are masked from 'package:datasets':
##
## cars, trees
library(tidycensus)
library(tidyverse)
## ── Attaching packages ─── tidyverse 1.2.1 ──
## ✔ ggplot2 3.0.0 ✔ purrr 0.2.5
## ✔ tibble 1.4.2 ✔ dplyr 0.7.6
## ✔ tidyr 0.8.1 ✔ stringr 1.3.1
## ✔ readr 1.1.1 ✔ forcats 0.3.0
## ── Conflicts ────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
library(viridis)
## Loading required package: viridisLite
library(stringr)
centroids <- read_delim("~/Dropbox/Documents/SMU/CSC 463/Fall 2017 Main/centroids.txt",
"\t", escape_double = FALSE, col_types = cols(GEOID = col_character()),
trim_ws = TRUE)
Let’s look at median household income in the last 12 months for the State of Washington using ACS 2016 5 year estimates.
options(tigris_use_cache = TRUE)
medhh <- get_acs(state = "WA", geography = "county",
variables = "B19013_001", geometry = TRUE)
## Getting data from the 2012-2016 5-year ACS
head(medhh)
## Simple feature collection with 6 features and 5 fields
## geometry type: MULTIPOLYGON
## dimension: XY
## bbox: xmin: -124.7631 ymin: 45.54354 xmax: -116.916 ymax: 48.55084
## epsg (SRID): 4269
## proj4string: +proj=longlat +datum=NAD83 +no_defs
## GEOID NAME variable estimate moe
## 1 53001 Adams County, Washington B19013_001 47554 3932
## 2 53003 Asotin County, Washington B19013_001 45550 3145
## 3 53005 Benton County, Washington B19013_001 61147 1232
## 4 53007 Chelan County, Washington B19013_001 51845 2267
## 5 53009 Clallam County, Washington B19013_001 47180 1585
## 6 53011 Clark County, Washington B19013_001 62879 1129
## geometry
## 1 MULTIPOLYGON (((-119.3694 4...
## 2 MULTIPOLYGON (((-117.48 46....
## 3 MULTIPOLYGON (((-119.8751 4...
## 4 MULTIPOLYGON (((-121.1789 4...
## 5 MULTIPOLYGON (((-124.6022 4...
## 6 MULTIPOLYGON (((-122.796 45...
medhh %>%
mutate(NAME = str_replace(NAME,'County, Washington','')) %>%
ggplot(aes(x = estimate, y = reorder(NAME, estimate))) +
geom_point()
medhh %>%
ggplot(aes(fill = estimate, color = estimate)) +
geom_sf() +
coord_sf(crs = 26911) +
scale_fill_viridis(option = "magma") +
scale_color_viridis(option = "magma")
cc = countyComplete %>%
filter(state == "Washington") %>%
select(FIPS,pop2010) %>%
rename(GEOID = FIPS) %>%
mutate(GEOID = as.character(GEOID))
select(centroids,GEOID,LAT,LONG) %>%
full_join(cc) %>%
full_join(medhh) -> medhhc
## Joining, by = "GEOID"
## Joining, by = "GEOID"
medhhc %>% ggplot(aes(x=LONG,y=LAT)) +
geom_sf() +
geom_point(aes(color=estimate,size=pop2010)) +
scale_color_viridis(option = "magma")