Physical world
Physical world
Social world
Some socio-economic-political variables that could be mapped onto physical, geographical features
E.g., district-level income level, crime rate, education spending, etc
Physical world
Social world
Some socio-economic-political variables that could be mapped onto physical, geographical features
E.g., district-level income level, crime rate, education spending, etc
Graphical space as dimension(s) to express some variables
We can project (1) physical space onto (3) graphical space
We can project (1) physical space onto (3) graphical space
We can project (2) social variables directly onto (3) graphical space
We can project (1) physical space onto (3) graphical space
We can project (2) social variables directly onto (3) graphical space
Problems start to occur when we project (2) social variables onto (1) physical space, then onto (3) graphical space
We can project (1) physical space onto (3) graphical space
We can project (2) social variables directly onto (3) graphical space
Problems start to occur when we project (2) social variables onto (1) physical space, then onto (3) graphical space
Let's say we want to visualize some district-level covariates
Problem 1: incongruity b/w social space and physical space
We visualize district-level variables onto the whole WA state; too much extrapolation
We can project (1) physical space onto (3) graphical space
We can project (2) social variables directly onto (3) graphical space
Problems start to occur when we project (2) social variables onto (1) physical space, then onto (3) graphical space
Let's say we want to visualize some district-level covariates
Problem 1: incongruity b/w social space and physical space
We visualize district-level variables onto the whole WA state; too much extrapolation
Problem 2: why do we prioritize physical space?
E.g., why a vast piece of land w/ little people should be prioritized over a small but densely populated area?
Can we use variables other than physical space to mediate (2) and (3)?
Cover different ways to visualize spatial data:
Geo-faceted small multiples w/ package geofacet
Cover different ways to visualize spatial data:
Geo-faceted small multiples w/ package geofacet
Cartogram heatmap w/ package statebins
Cover different ways to visualize spatial data:
Geo-faceted small multiples w/ package geofacet
Cartogram heatmap w/ package statebins
Tiled cartogram w/ package tilegramsR
Cover different ways to visualize spatial data:
Geo-faceted small multiples w/ package geofacet
Cartogram heatmap w/ package statebins
Tiled cartogram w/ package tilegramsR
Choropleth maps (a.k.a. "maps'')
Cover different ways to visualize spatial data:
Geo-faceted small multiples w/ package geofacet
Cartogram heatmap w/ package statebins
Tiled cartogram w/ package tilegramsR
Choropleth maps (a.k.a. "maps'')
.shp
)Cover different ways to visualize spatial data:
Geo-faceted small multiples w/ package geofacet
Cartogram heatmap w/ package statebins
Tiled cartogram w/ package tilegramsR
Choropleth maps (a.k.a. "maps'')
Brief introduction to spatial data file (e.g., shapefile; .shp
)
package sf
to wrangle spatial data and tmap
to visualize map
Cover different ways to visualize spatial data:
Geo-faceted small multiples w/ package geofacet
Cartogram heatmap w/ package statebins
Tiled cartogram w/ package tilegramsR
Choropleth maps (a.k.a. "maps'')
Brief introduction to spatial data file (e.g., shapefile; .shp
)
package sf
to wrangle spatial data and tmap
to visualize map
Interactive maps; small multiples in choropleth maps
Cover different ways to visualize spatial data:
Geo-faceted small multiples w/ package geofacet
Cartogram heatmap w/ package statebins
Tiled cartogram w/ package tilegramsR
Choropleth maps (a.k.a. "maps'')
Brief introduction to spatial data file (e.g., shapefile; .shp
)
package sf
to wrangle spatial data and tmap
to visualize map
Interactive maps; small multiples in choropleth maps
Be mindful of the issues of space(s) and the curse of dimensionality
Cover different ways to visualize spatial data:
Geo-faceted small multiples w/ package geofacet
Cartogram heatmap w/ package statebins
Tiled cartogram w/ package tilegramsR
Choropleth maps (a.k.a. "maps'')
Brief introduction to spatial data file (e.g., shapefile; .shp
)
package sf
to wrangle spatial data and tmap
to visualize map
Interactive maps; small multiples in choropleth maps
Be mindful of the issues of space(s) and the curse of dimensionality
# download packages packages <- c("tidyverse", "geofacet", "statebins", "tilegramsR", "sf", "tmap", "tigris")not_installed <- setdiff(packages, rownames(installed.packages()))if (length(not_installed)) install.packages(not_installed)# load packageslibrary(tidyverse)library(geofacet)library(statebins)library(tilegramsR)library(sf)library(tmap)library(maptiles)library(tigris)# load themesource("https://students.washington.edu/kpleung/vis/theme_cavis.R")
WaPo_data <- read_csv("data/WaPo_data.csv")
WaPo_data <- read_csv("data/WaPo_data.csv")print(WaPo_data, n = 5)
# A tibble: 51 × 23 stab state share_cut1994 share_cut1995 share_cut1996 share_cut1997 <chr> <chr> <dbl> <dbl> <dbl> <dbl>1 NC North Carolina 1.4 0.9 3 4.12 AL Alabama 1.1 2.4 5.2 4.63 MS Mississippi 2 3.9 5.1 2.24 AR Arkansas 1.6 1.3 1.6 2.75 TN Tennessee 1.6 2 3.4 3.5# ℹ 46 more rows# ℹ 17 more variables: share_cut1998 <dbl>, share_cut1999 <dbl>,# share_cut2000 <dbl>, share_cut2001 <dbl>, share_cut2002 <dbl>,# share_cut2003 <dbl>, share_cut2004 <dbl>, share_cut2005 <dbl>,# share_cut2006 <dbl>, share_cut2007 <dbl>, share_cut2008 <dbl>,# share_cut2009 <dbl>, share_cut2010 <dbl>, share_cut2011 <dbl>,# share_cut2012 <dbl>, share_cut2013 <dbl>, avgshare <dbl>
# convert the data into long formatWaPo_data
# A tibble: 51 × 23 stab state share_cut1994 share_cut1995 share_cut1996 share_cut1997 <chr> <chr> <dbl> <dbl> <dbl> <dbl> 1 NC North Carolina 1.4 0.9 3 4.1 2 AL Alabama 1.1 2.4 5.2 4.6 3 MS Mississippi 2 3.9 5.1 2.2 4 AR Arkansas 1.6 1.3 1.6 2.7 5 TN Tennessee 1.6 2 3.4 3.5 6 SC South Carolina 1.5 1 2.5 0.7 7 ME Maine 2.3 1.9 3.5 1.7 8 MI Michigan 0.3 0.4 1.1 0.9 9 OR Oregon 0.4 0.7 1.3 0.810 KY Kentucky 2.5 1 3.1 1.8# ℹ 41 more rows# ℹ 17 more variables: share_cut1998 <dbl>, share_cut1999 <dbl>,# share_cut2000 <dbl>, share_cut2001 <dbl>, share_cut2002 <dbl>,# share_cut2003 <dbl>, share_cut2004 <dbl>, share_cut2005 <dbl>,# share_cut2006 <dbl>, share_cut2007 <dbl>, share_cut2008 <dbl>,# share_cut2009 <dbl>, share_cut2010 <dbl>, share_cut2011 <dbl>,# share_cut2012 <dbl>, share_cut2013 <dbl>, avgshare <dbl>
# convert the data into long formatWaPo_data %>% select(-avgshare)
# A tibble: 51 × 22 stab state share_cut1994 share_cut1995 share_cut1996 share_cut1997 <chr> <chr> <dbl> <dbl> <dbl> <dbl> 1 NC North Carolina 1.4 0.9 3 4.1 2 AL Alabama 1.1 2.4 5.2 4.6 3 MS Mississippi 2 3.9 5.1 2.2 4 AR Arkansas 1.6 1.3 1.6 2.7 5 TN Tennessee 1.6 2 3.4 3.5 6 SC South Carolina 1.5 1 2.5 0.7 7 ME Maine 2.3 1.9 3.5 1.7 8 MI Michigan 0.3 0.4 1.1 0.9 9 OR Oregon 0.4 0.7 1.3 0.810 KY Kentucky 2.5 1 3.1 1.8# ℹ 41 more rows# ℹ 16 more variables: share_cut1998 <dbl>, share_cut1999 <dbl>,# share_cut2000 <dbl>, share_cut2001 <dbl>, share_cut2002 <dbl>,# share_cut2003 <dbl>, share_cut2004 <dbl>, share_cut2005 <dbl>,# share_cut2006 <dbl>, share_cut2007 <dbl>, share_cut2008 <dbl>,# share_cut2009 <dbl>, share_cut2010 <dbl>, share_cut2011 <dbl>,# share_cut2012 <dbl>, share_cut2013 <dbl>
# convert the data into long formatWaPo_data %>% select(-avgshare) %>% pivot_longer(contains("share_cut"), names_to = "year", values_to = "share_cut")
# A tibble: 1,020 × 4 stab state year share_cut <chr> <chr> <chr> <dbl> 1 NC North Carolina share_cut1994 1.4 2 NC North Carolina share_cut1995 0.9 3 NC North Carolina share_cut1996 3 4 NC North Carolina share_cut1997 4.1 5 NC North Carolina share_cut1998 3 6 NC North Carolina share_cut1999 3.9 7 NC North Carolina share_cut2000 1.5 8 NC North Carolina share_cut2001 3.8 9 NC North Carolina share_cut2002 6.110 NC North Carolina share_cut2003 6.7# ℹ 1,010 more rows
# convert the data into long formatWaPo_data %>% select(-avgshare) %>% pivot_longer(contains("share_cut"), names_to = "year", values_to = "share_cut") %>% mutate(year = str_extract(year, "\\d+"), year = as.numeric(year))
# A tibble: 1,020 × 4 stab state year share_cut <chr> <chr> <dbl> <dbl> 1 NC North Carolina 1994 1.4 2 NC North Carolina 1995 0.9 3 NC North Carolina 1996 3 4 NC North Carolina 1997 4.1 5 NC North Carolina 1998 3 6 NC North Carolina 1999 3.9 7 NC North Carolina 2000 1.5 8 NC North Carolina 2001 3.8 9 NC North Carolina 2002 6.110 NC North Carolina 2003 6.7# ℹ 1,010 more rows
# convert the data into long formatWaPo_data %>% select(-avgshare) %>% pivot_longer(contains("share_cut"), names_to = "year", values_to = "share_cut") %>% mutate(year = str_extract(year, "\\d+"), year = as.numeric(year)) -> WaPo_data_long
ggplot(WaPo_data_long, aes(x = year , y = share_cut))
ggplot(WaPo_data_long, aes(x = year , y = share_cut)) + theme_cavis_hgrid
ggplot(WaPo_data_long, aes(x = year , y = share_cut)) + theme_cavis_hgrid + geom_line()
ggplot(WaPo_data_long, aes(x = year , y = share_cut)) + theme_cavis_hgrid + geom_line() + facet_wrap(~ state)
ggplot(WaPo_data_long, aes(x = year , y = share_cut)) + theme_cavis_hgrid + geom_line() + facet_wrap(~ state) + scale_x_continuous( labels = function(x) paste0("'", str_sub(x, 3, 4)) )
ggplot(WaPo_data_long, aes(x = year , y = share_cut)) + theme_cavis_hgrid + geom_line() + facet_wrap(~ state) + scale_x_continuous( labels = function(x) paste0("'", str_sub(x, 3, 4)) ) + scale_y_continuous( labels = function(x) paste0(x, "%") )
ggplot(WaPo_data_long, aes(x = year , y = share_cut)) + theme_cavis_hgrid + geom_line() + facet_wrap(~ state) + scale_x_continuous( labels = function(x) paste0("'", str_sub(x, 3, 4)) ) + scale_y_continuous( labels = function(x) paste0(x, "%") ) + theme( strip.text.x = element_text(size = 7), axis.text.x = element_text(size = 7), axis.text.y = element_text(size = 7) )
ggplot(WaPo_data_long, aes(x = year , y = share_cut)) + theme_cavis_hgrid + geom_line() + facet_wrap(~ state) + scale_x_continuous( labels = function(x) paste0("'", str_sub(x, 3, 4)) ) + scale_y_continuous( labels = function(x) paste0(x, "%") ) + theme( strip.text.x = element_text(size = 7), axis.text.x = element_text(size = 7), axis.text.y = element_text(size = 7) ) + labs(x = NULL, y = "Share of job loss due to trade")
ggplot(WaPo_data_long, aes(x = year , y = share_cut)) + theme_cavis_hgrid + geom_line() + facet_geo(~ state, grid = "us_state_grid2") + scale_x_continuous( labels = function(x) paste0("'", str_sub(x, 3, 4)) ) + scale_y_continuous( labels = function(x) paste0(x, "%") ) + theme( strip.text.x = element_text(size = 7), axis.text.x = element_text(size = 7), axis.text.y = element_text(size = 7) ) + labs(x = NULL, y = "Share of job loss due to trade")
ggplot(WaPo_data_long, aes(x = year , y = share_cut)) + theme_cavis_hgrid + geom_line() + facet_geo(~ state, grid = "us_state_grid1") + scale_x_continuous( labels = function(x) paste0("'", str_sub(x, 3, 4)) ) + scale_y_continuous( labels = function(x) paste0(x, "%") ) + theme( strip.text.x = element_text(size = 7), axis.text.x = element_text(size = 7), axis.text.y = element_text(size = 7) ) + labs(x = NULL, y = "Share of job loss due to trade")
Check out the available grids (users submitted)
You can build your own grid using Geo Grid Designer and make it a public good
# coerce avgshare into a factorWaPo_data
# A tibble: 51 × 23 stab state share_cut1994 share_cut1995 share_cut1996 share_cut1997 <chr> <chr> <dbl> <dbl> <dbl> <dbl> 1 NC North Carolina 1.4 0.9 3 4.1 2 AL Alabama 1.1 2.4 5.2 4.6 3 MS Mississippi 2 3.9 5.1 2.2 4 AR Arkansas 1.6 1.3 1.6 2.7 5 TN Tennessee 1.6 2 3.4 3.5 6 SC South Carolina 1.5 1 2.5 0.7 7 ME Maine 2.3 1.9 3.5 1.7 8 MI Michigan 0.3 0.4 1.1 0.9 9 OR Oregon 0.4 0.7 1.3 0.810 KY Kentucky 2.5 1 3.1 1.8# ℹ 41 more rows# ℹ 17 more variables: share_cut1998 <dbl>, share_cut1999 <dbl>,# share_cut2000 <dbl>, share_cut2001 <dbl>, share_cut2002 <dbl>,# share_cut2003 <dbl>, share_cut2004 <dbl>, share_cut2005 <dbl>,# share_cut2006 <dbl>, share_cut2007 <dbl>, share_cut2008 <dbl>,# share_cut2009 <dbl>, share_cut2010 <dbl>, share_cut2011 <dbl>,# share_cut2012 <dbl>, share_cut2013 <dbl>, avgshare <dbl>
# coerce avgshare into a factorWaPo_data %>% select(stab, state, avgshare)
# A tibble: 51 × 3 stab state avgshare <chr> <chr> <dbl> 1 NC North Carolina 3.56 2 AL Alabama 3.22 3 MS Mississippi 2.94 4 AR Arkansas 2.89 5 TN Tennessee 2.86 6 SC South Carolina 2.61 7 ME Maine 2.58 8 MI Michigan 2.55 9 OR Oregon 2.3810 KY Kentucky 2.24# ℹ 41 more rows
# coerce avgshare into a factorWaPo_data %>% select(stab, state, avgshare) %>% mutate(avgshare2 = cut(avgshare, breaks = 4, labels = c("0-1", "1-2", "2-3", "3-4")))
# A tibble: 51 × 4 stab state avgshare avgshare2 <chr> <chr> <dbl> <fct> 1 NC North Carolina 3.56 3-4 2 AL Alabama 3.22 3-4 3 MS Mississippi 2.94 3-4 4 AR Arkansas 2.89 3-4 5 TN Tennessee 2.86 3-4 6 SC South Carolina 2.61 2-3 7 ME Maine 2.58 2-3 8 MI Michigan 2.55 2-3 9 OR Oregon 2.38 2-3 10 KY Kentucky 2.24 2-3 # ℹ 41 more rows
# coerce avgshare into a factorWaPo_data %>% select(stab, state, avgshare) %>% mutate(avgshare2 = cut(avgshare, breaks = 4, labels = c("0-1", "1-2", "2-3", "3-4"))) -> WaPo_data2
WaPo_data2
# A tibble: 51 × 4 stab state avgshare avgshare2 <chr> <chr> <dbl> <fct> 1 NC North Carolina 3.56 3-4 2 AL Alabama 3.22 3-4 3 MS Mississippi 2.94 3-4 4 AR Arkansas 2.89 3-4 5 TN Tennessee 2.86 3-4 6 SC South Carolina 2.61 2-3 7 ME Maine 2.58 2-3 8 MI Michigan 2.55 2-3 9 OR Oregon 2.38 2-3 10 KY Kentucky 2.24 2-3 # ℹ 41 more rows
WaPo_data2 %>% statebins( value_col = "avgshare2", ggplot2_scale_function = scale_fill_brewer, )
WaPo_data2 %>% statebins( value_col = "avgshare2", ggplot2_scale_function = scale_fill_brewer, ) + theme_statebins()
WaPo_data2 %>% statebins( value_col = "avgshare2", ggplot2_scale_function = scale_fill_brewer, round = TRUE ) + theme_statebins()
WaPo_data2 %>% statebins( value_col = "avgshare2", ggplot2_scale_function = scale_fill_brewer, round = TRUE ) + theme_statebins() + scale_fill_brewer( palette = "Blues", labels = c("Smallest\nshare", "", "", "Largest"), name = "Share of job loss due to trade")
WaPo_data2 %>% statebins( value_col = "avgshare2", ggplot2_scale_function = scale_fill_brewer, round = TRUE ) + theme_statebins() + scale_fill_brewer( palette = "Blues", labels = c("Smallest\nshare", "", "", "Largest"), name = "Share of job loss due to trade") + guides(fill = guide_legend(title.position = "top", label.position = "bottom"))
WaPo_data2 %>% statebins( value_col = "avgshare2", ggplot2_scale_function = scale_fill_brewer, round = TRUE ) + theme_statebins() + scale_fill_brewer( palette = "Blues", labels = c("Smallest\nshare", "", "", "Largest"), name = "Share of job loss due to trade") + guides(fill = guide_legend(title.position = "top", label.position = "bottom")) + theme(legend.position = c(0, 0.85), legend.direction = "horizontal", )
WaPo_data2 %>% statebins( value_col = "avgshare2", ggplot2_scale_function = scale_fill_brewer, round = TRUE ) + theme_statebins() + scale_fill_brewer( palette = "Blues", labels = c("Smallest\nshare", "", "", "Largest"), name = "Share of job loss due to trade") + guides(fill = guide_legend(title.position = "top", label.position = "bottom")) + theme(legend.position = c(0, 0.85), legend.direction = "horizontal", legend.key.height = unit(0.2, "cm"), legend.key.width = unit(1.6, "cm") )
The statebins
package only supports the United States data at the moment
But customizing grid should be easy to implement, like geofacet
package?
ec_tiles <- tilegramsR::sf_FiveThirtyEightElectoralCollege
ec_tiles <- tilegramsR::sf_FiveThirtyEightElectoralCollegeclass(ec_tiles) # more on sf obejct soon
[1] "sf" "data.frame"
ec_tiles <- tilegramsR::sf_FiveThirtyEightElectoralCollegeclass(ec_tiles) # more on sf obejct soonec_tiles
[1] "sf" "data.frame"
Simple feature collection with 538 features and 3 fieldsGeometry type: POLYGONDimension: XYBounding box: xmin: 293.6239 ymin: 16.95238 xmax: 2495.803 ymax: 1661.333CRS: NAFirst 10 features: FID state tilegramVa geometry1 02 AK 3 POLYGON ((293.6239 237.3333...2 06 CA 55 POLYGON ((352.3486 847.619,...3 06 CA 55 POLYGON ((322.9862 796.7619...4 06 CA 55 POLYGON ((352.3486 745.9048...5 06 CA 55 POLYGON ((322.9862 695.0476...6 06 CA 55 POLYGON ((352.3486 644.1905...7 02 AK 3 POLYGON ((322.9862 288.1905...8 02 AK 3 POLYGON ((352.3486 237.3333...9 06 CA 55 POLYGON ((411.0734 949.3333...10 06 CA 55 POLYGON ((381.711 898.4762,...
ec_tiles <- tilegramsR::sf_FiveThirtyEightElectoralCollegeclass(ec_tiles) # more on sf obejct soonec_tiles %>% left_join(WaPo_data2, by = c("state" = "stab"))
[1] "sf" "data.frame"
Simple feature collection with 538 features and 6 fieldsGeometry type: POLYGONDimension: XYBounding box: xmin: 293.6239 ymin: 16.95238 xmax: 2495.803 ymax: 1661.333CRS: NAFirst 10 features: FID state tilegramVa state.y avgshare avgshare21 02 AK 3 Alaska 1.88 2-32 06 CA 55 California 0.72 0-13 06 CA 55 California 0.72 0-14 06 CA 55 California 0.72 0-15 06 CA 55 California 0.72 0-16 06 CA 55 California 0.72 0-17 02 AK 3 Alaska 1.88 2-38 02 AK 3 Alaska 1.88 2-39 06 CA 55 California 0.72 0-110 06 CA 55 California 0.72 0-1 geometry1 POLYGON ((293.6239 237.3333...2 POLYGON ((352.3486 847.619,...3 POLYGON ((322.9862 796.7619...4 POLYGON ((352.3486 745.9048...5 POLYGON ((322.9862 695.0476...6 POLYGON ((352.3486 644.1905...7 POLYGON ((322.9862 288.1905...8 POLYGON ((352.3486 237.3333...9 POLYGON ((411.0734 949.3333...10 POLYGON ((381.711 898.4762,...
ec_tiles <- tilegramsR::sf_FiveThirtyEightElectoralCollegeclass(ec_tiles) # more on sf obejct soonec_tiles %>% left_join(WaPo_data2, by = c("state" = "stab")) -> ec_tiles
[1] "sf" "data.frame"
ec_tiles <- tilegramsR::sf_FiveThirtyEightElectoralCollegeclass(ec_tiles) # more on sf obejct soonec_tiles %>% left_join(WaPo_data2, by = c("state" = "stab")) -> ec_tilesstate_tiles <- sf_FiveThirtyEightElectoralCollege.states # state polygons for drawing borders
[1] "sf" "data.frame"
ec_tiles <- tilegramsR::sf_FiveThirtyEightElectoralCollegeclass(ec_tiles) # more on sf obejct soonec_tiles %>% left_join(WaPo_data2, by = c("state" = "stab")) -> ec_tilesstate_tiles <- sf_FiveThirtyEightElectoralCollege.states # state polygons for drawing bordersec_centers <- sf_FiveThirtyEightElectoralCollege.centers # state centroids for drawing labels
[1] "sf" "data.frame"
ggplot() + theme_void()
ggplot() + theme_void() + geom_sf( data = ec_tiles, )
ggplot() + theme_void() + geom_sf( data = ec_tiles, aes( fill = avgshare2, ) )
ggplot() + theme_void() + geom_sf( data = ec_tiles, aes( fill = avgshare2, color = avgshare2 ) )
ggplot() + theme_void() + geom_sf( data = ec_tiles, aes( fill = avgshare2, color = avgshare2 ) ) + scale_fill_brewer(palette = "Blues", name = "Share of job loss\ndue to trade")
ggplot() + theme_void() + geom_sf( data = ec_tiles, aes( fill = avgshare2, color = avgshare2 ) ) + scale_fill_brewer(palette = "Blues", name = "Share of job loss\ndue to trade") + scale_color_brewer(palette = "Blues", name = "Share of job loss\ndue to trade")
ggplot() + theme_void() + geom_sf( data = ec_tiles, aes( fill = avgshare2, color = avgshare2 ) ) + scale_fill_brewer(palette = "Blues", name = "Share of job loss\ndue to trade") + scale_color_brewer(palette = "Blues", name = "Share of job loss\ndue to trade") + geom_sf_text( data = ec_centers, aes(label = state) )
ggplot() + theme_void() + geom_sf( data = ec_tiles, aes( fill = avgshare2, color = avgshare2 ) ) + scale_fill_brewer(palette = "Blues", name = "Share of job loss\ndue to trade") + scale_color_brewer(palette = "Blues", name = "Share of job loss\ndue to trade") + geom_sf_text( data = ec_centers, aes(label = state) ) + geom_sf( data = state_tiles, color = "white", alpha = 0 )
ggplot() + theme_void() + geom_sf( data = ec_tiles, aes( fill = avgshare2, color = avgshare2 ) ) + scale_fill_brewer(palette = "Blues", name = "Share of job loss\ndue to trade") + scale_color_brewer(palette = "Blues", name = "Share of job loss\ndue to trade") + geom_sf_text( data = ec_centers, aes(label = state) ) + geom_sf( data = state_tiles, color = "white", alpha = 0 ) + theme(legend.position = c(0.925, 0.25))
Why hexagos? Because hexagons are the bestagons
To my knowledge, there is no existing algorithm to automatically generate the tile cartogram layouts
Why hexagos? Because hexagons are the bestagons
To my knowledge, there is no existing algorithm to automatically generate the tile cartogram layouts
I'm trying to develop a function/package to do that: inspirations from using neural networks/ genetic algorithms to solve the Tetris game
Numerous spatial data formats
.shp
(shapefile; the most common); .geojson
, .json
; .gml
; .csv
; .tiff
...Numerous spatial data formats
.shp
(shapefile; the most common); .geojson
, .json
; .gml
; .csv
; .tiff
...Countless packages to work with spatial data
Numerous spatial data formats
.shp
(shapefile; the most common); .geojson
, .json
; .gml
; .csv
; .tiff
...Countless packages to work with spatial data
sf
allows geospatial data to be stored in data frames Numerous spatial data formats
.shp
(shapefile; the most common); .geojson
, .json
; .gml
; .csv
; .tiff
...Countless packages to work with spatial data
Recent package sf
allows geospatial data to be stored in data frames
Well integrated with tidyverse
Numerous spatial data formats
.shp
(shapefile; the most common); .geojson
, .json
; .gml
; .csv
; .tiff
...Countless packages to work with spatial data
Recent package sf
allows geospatial data to be stored in data frames
Well integrated with tidyverse
Many packages to draw maps
Numerous spatial data formats
.shp
(shapefile; the most common); .geojson
, .json
; .gml
; .csv
; .tiff
...Countless packages to work with spatial data
Recent package sf
allows geospatial data to be stored in data frames
Well integrated with tidyverse
Many packages to draw maps
tmap
allows easy visualization of static and interactive mapsNumerous spatial data formats
.shp
(shapefile; the most common); .geojson
, .json
; .gml
; .csv
; .tiff
...Countless packages to work with spatial data
Recent package sf
allows geospatial data to be stored in data frames
Well integrated with tidyverse
Many packages to draw maps
tmap
allows easy visualization of static and interactive maps
Also employs the "grammar of graphics"
tmap
:ggplot2 | tmap | |
---|---|---|
Data | ggplot(...) + |
tm_shape(...) + |
Layers | geom_...(...) + |
tm_...(...) + |
Small Multiples | facet_grid(...) |
tm_facets(...) |
Layout | theme(...) |
tm_layout(...) |
Before plotting choropleth maps, we need to find the appropriate shapefile
Download the US shapefile here
us_shp <- st_read("data/cb_2018_us_state_20m/cb_2018_us_state_20m.shp")
Reading layer `cb_2018_us_state_20m' from data source `D:\Google Drive\Phd UW\Courses\5th year\CS&SS 569 - Visualizing Data and Models\Labs\Lab6\data\cb_2018_us_state_20m\cb_2018_us_state_20m.shp' using driver `ESRI Shapefile'Simple feature collection with 52 features and 9 fieldsGeometry type: MULTIPOLYGONDimension: XYBounding box: xmin: -179.1743 ymin: 17.91377 xmax: 179.7739 ymax: 71.35256Geodetic CRS: NAD83
us_shp <- st_read("data/cb_2018_us_state_20m/cb_2018_us_state_20m.shp")class(us_shp)
Reading layer `cb_2018_us_state_20m' from data source `D:\Google Drive\Phd UW\Courses\5th year\CS&SS 569 - Visualizing Data and Models\Labs\Lab6\data\cb_2018_us_state_20m\cb_2018_us_state_20m.shp' using driver `ESRI Shapefile'Simple feature collection with 52 features and 9 fieldsGeometry type: MULTIPOLYGONDimension: XYBounding box: xmin: -179.1743 ymin: 17.91377 xmax: 179.7739 ymax: 71.35256Geodetic CRS: NAD83
[1] "sf" "data.frame"
us_shp <- st_read("data/cb_2018_us_state_20m/cb_2018_us_state_20m.shp")class(us_shp)head(as_tibble(us_shp))
Reading layer `cb_2018_us_state_20m' from data source `D:\Google Drive\Phd UW\Courses\5th year\CS&SS 569 - Visualizing Data and Models\Labs\Lab6\data\cb_2018_us_state_20m\cb_2018_us_state_20m.shp' using driver `ESRI Shapefile'Simple feature collection with 52 features and 9 fieldsGeometry type: MULTIPOLYGONDimension: XYBounding box: xmin: -179.1743 ymin: 17.91377 xmax: 179.7739 ymax: 71.35256Geodetic CRS: NAD83
[1] "sf" "data.frame"
# A tibble: 6 × 10 STATEFP STATENS AFFGEOID GEOID STUSPS NAME LSAD ALAND AWATER <chr> <chr> <chr> <chr> <chr> <chr> <chr> <dbl> <dbl>1 24 01714934 0400000US24 24 MD Maryland 00 2.52e10 6.98e 92 19 01779785 0400000US19 19 IA Iowa 00 1.45e11 1.08e 93 10 01779781 0400000US10 10 DE Delaware 00 5.05e 9 1.40e 94 39 01085497 0400000US39 39 OH Ohio 00 1.06e11 1.03e105 42 01779798 0400000US42 42 PA Pennsylvania 00 1.16e11 3.39e 96 31 01779792 0400000US31 31 NE Nebraska 00 1.99e11 1.37e 9# ℹ 1 more variable: geometry <MULTIPOLYGON [°]>
us_shp
Simple feature collection with 52 features and 9 fieldsGeometry type: MULTIPOLYGONDimension: XYBounding box: xmin: -179.1743 ymin: 17.91377 xmax: 179.7739 ymax: 71.35256Geodetic CRS: NAD83First 10 features: STATEFP STATENS AFFGEOID GEOID STUSPS NAME LSAD ALAND1 24 01714934 0400000US24 24 MD Maryland 00 251511002802 19 01779785 0400000US19 19 IA Iowa 00 1446612679773 10 01779781 0400000US10 10 DE Delaware 00 50459256464 39 01085497 0400000US39 39 OH Ohio 00 1058288825685 42 01779798 0400000US42 42 PA Pennsylvania 00 1158844423216 31 01779792 0400000US31 31 NE Nebraska 00 1989566583957 53 01779804 0400000US53 53 WA Washington 00 1721125882208 72 01779808 0400000US72 72 PR Puerto Rico 00 88688960309 01 01779775 0400000US01 01 AL Alabama 00 13117404858310 05 00068085 0400000US05 05 AR Arkansas 00 134768872727 AWATER geometry1 6979966958 MULTIPOLYGON (((-76.04621 3...2 1084180812 MULTIPOLYGON (((-96.62187 4...3 1399985648 MULTIPOLYGON (((-75.77379 3...4 10268850702 MULTIPOLYGON (((-82.86334 4...5 3394589990 MULTIPOLYGON (((-80.51989 4...6 1371829134 MULTIPOLYGON (((-104.0531 4...7 12559278850 MULTIPOLYGON (((-123.2371 4...8 4922382562 MULTIPOLYGON (((-65.34207 1...9 4593327154 MULTIPOLYGON (((-88.46866 3...10 2962859592 MULTIPOLYGON (((-94.61792 3...
us_shp %>% left_join(WaPo_data, by=c("NAME" = "state"))
Simple feature collection with 52 features and 31 fieldsGeometry type: MULTIPOLYGONDimension: XYBounding box: xmin: -179.1743 ymin: 17.91377 xmax: 179.7739 ymax: 71.35256Geodetic CRS: NAD83First 10 features: STATEFP STATENS AFFGEOID GEOID STUSPS NAME LSAD ALAND1 24 01714934 0400000US24 24 MD Maryland 00 251511002802 19 01779785 0400000US19 19 IA Iowa 00 1446612679773 10 01779781 0400000US10 10 DE Delaware 00 50459256464 39 01085497 0400000US39 39 OH Ohio 00 1058288825685 42 01779798 0400000US42 42 PA Pennsylvania 00 1158844423216 31 01779792 0400000US31 31 NE Nebraska 00 1989566583957 53 01779804 0400000US53 53 WA Washington 00 1721125882208 72 01779808 0400000US72 72 PR Puerto Rico 00 88688960309 01 01779775 0400000US01 01 AL Alabama 00 13117404858310 05 00068085 0400000US05 05 AR Arkansas 00 134768872727 AWATER stab share_cut1994 share_cut1995 share_cut1996 share_cut19971 6979966958 MD 0.4 1.1 0.7 0.42 1084180812 IA 0.1 0.4 0.5 0.63 1399985648 DE 0.6 0.0 0.0 0.04 10268850702 OH 0.6 0.8 0.6 1.05 3394589990 PA 1.5 1.4 2.0 1.76 1371829134 NE 0.0 0.2 0.7 0.17 12559278850 WA 1.0 1.2 0.5 0.48 4922382562 <NA> NA NA NA NA9 4593327154 AL 1.1 2.4 5.2 4.610 2962859592 AR 1.6 1.3 1.6 2.7 share_cut1998 share_cut1999 share_cut2000 share_cut2001 share_cut20021 0.5 0.4 0.3 0.1 0.32 0.1 0.5 0.1 0.6 0.93 0.0 0.4 0.0 0.0 0.04 0.5 1.0 0.9 1.3 2.55 1.5 1.3 1.4 3.6 2.86 0.1 0.2 1.0 0.0 0.67 1.0 0.7 2.5 1.4 9.48 NA NA NA NA NA9 3.5 5.6 2.5 2.8 6.510 2.7 2.8 0.6 3.1 3.9 share_cut2003 share_cut2004 share_cut2005 share_cut2006 share_cut20071 1.1 0.1 0.5 0.7 0.82 0.9 1.0 0.6 2.4 0.93 1.0 0.9 0.7 0.4 0.14 1.9 1.4 0.9 2.9 2.05 2.8 1.2 1.5 0.9 1.66 2.0 1.2 0.2 0.2 0.97 1.3 3.4 0.6 0.4 0.68 NA NA NA NA NA9 2.2 2.1 1.2 3.3 2.610 3.6 1.1 2.3 3.8 4.9 share_cut2008 share_cut2009 share_cut2010 share_cut2011 share_cut20121 0.5 0.2 0.6 0.8 0.32 0.8 2.3 1.4 1.4 0.23 0.0 5.4 0.0 0.0 0.04 2.2 5.0 2.8 1.0 1.35 1.0 2.6 2.5 0.9 1.16 0.3 1.3 0.3 1.1 0.17 0.7 2.2 1.6 1.1 1.08 NA NA NA NA NA9 3.9 4.3 3.6 0.4 0.710 3.2 3.0 3.3 2.4 3.9 share_cut2013 avgshare geometry1 0.1 0.47 MULTIPOLYGON (((-76.04621 3...2 1.1 0.89 MULTIPOLYGON (((-96.62187 4...3 0.1 0.53 MULTIPOLYGON (((-75.77379 3...4 0.4 1.72 MULTIPOLYGON (((-82.86334 4...5 0.8 1.79 MULTIPOLYGON (((-80.51989 4...6 0.5 0.62 MULTIPOLYGON (((-104.0531 4...7 0.7 1.69 MULTIPOLYGON (((-123.2371 4...8 NA NA MULTIPOLYGON (((-65.34207 1...9 0.6 3.22 MULTIPOLYGON (((-88.46866 3...10 0.5 2.89 MULTIPOLYGON (((-94.61792 3...
us_shp %>% left_join(WaPo_data, by=c("NAME" = "state")) %>% tigris::shift_geometry() # rescale AK, HI, PR
Simple feature collection with 52 features and 31 fieldsGeometry type: MULTIPOLYGONDimension: XYBounding box: xmin: -3112200 ymin: -1697728 xmax: 2258154 ymax: 1558935Projected CRS: USA_Contiguous_Albers_Equal_Area_ConicFirst 10 features: STATEFP STATENS AFFGEOID GEOID STUSPS NAME LSAD ALAND1 24 01714934 0400000US24 24 MD Maryland 00 251511002802 19 01779785 0400000US19 19 IA Iowa 00 1446612679773 10 01779781 0400000US10 10 DE Delaware 00 50459256464 39 01085497 0400000US39 39 OH Ohio 00 1058288825685 42 01779798 0400000US42 42 PA Pennsylvania 00 1158844423216 31 01779792 0400000US31 31 NE Nebraska 00 1989566583957 53 01779804 0400000US53 53 WA Washington 00 1721125882208 01 01779775 0400000US01 01 AL Alabama 00 1311740485839 05 00068085 0400000US05 05 AR Arkansas 00 13476887272710 35 00897535 0400000US35 35 NM New Mexico 00 314196306401 AWATER stab share_cut1994 share_cut1995 share_cut1996 share_cut19971 6979966958 MD 0.4 1.1 0.7 0.42 1084180812 IA 0.1 0.4 0.5 0.63 1399985648 DE 0.6 0.0 0.0 0.04 10268850702 OH 0.6 0.8 0.6 1.05 3394589990 PA 1.5 1.4 2.0 1.76 1371829134 NE 0.0 0.2 0.7 0.17 12559278850 WA 1.0 1.2 0.5 0.48 4593327154 AL 1.1 2.4 5.2 4.69 2962859592 AR 1.6 1.3 1.6 2.710 728776523 NM 1.4 0.8 0.9 3.0 share_cut1998 share_cut1999 share_cut2000 share_cut2001 share_cut20021 0.5 0.4 0.3 0.1 0.32 0.1 0.5 0.1 0.6 0.93 0.0 0.4 0.0 0.0 0.04 0.5 1.0 0.9 1.3 2.55 1.5 1.3 1.4 3.6 2.86 0.1 0.2 1.0 0.0 0.67 1.0 0.7 2.5 1.4 9.48 3.5 5.6 2.5 2.8 6.59 2.7 2.8 0.6 3.1 3.910 1.4 4.5 0.4 0.3 1.7 share_cut2003 share_cut2004 share_cut2005 share_cut2006 share_cut20071 1.1 0.1 0.5 0.7 0.82 0.9 1.0 0.6 2.4 0.93 1.0 0.9 0.7 0.4 0.14 1.9 1.4 0.9 2.9 2.05 2.8 1.2 1.5 0.9 1.66 2.0 1.2 0.2 0.2 0.97 1.3 3.4 0.6 0.4 0.68 2.2 2.1 1.2 3.3 2.69 3.6 1.1 2.3 3.8 4.910 0.5 0.1 0.1 0.1 0.0 share_cut2008 share_cut2009 share_cut2010 share_cut2011 share_cut20121 0.5 0.2 0.6 0.8 0.32 0.8 2.3 1.4 1.4 0.23 0.0 5.4 0.0 0.0 0.04 2.2 5.0 2.8 1.0 1.35 1.0 2.6 2.5 0.9 1.16 0.3 1.3 0.3 1.1 0.17 0.7 2.2 1.6 1.1 1.08 3.9 4.3 3.6 0.4 0.79 3.2 3.0 3.3 2.4 3.910 4.1 1.7 1.9 0.1 0.8 share_cut2013 avgshare geometry1 0.1 0.47 MULTIPOLYGON (((1722285 240...2 1.1 0.89 MULTIPOLYGON (((-50588.83 5...3 0.1 0.53 MULTIPOLYGON (((1705278 431...4 0.4 1.72 MULTIPOLYGON (((1081987 544...5 0.8 1.79 MULTIPOLYGON (((1287712 486...6 0.5 0.62 MULTIPOLYGON (((-670097.4 4...7 0.7 1.69 MULTIPOLYGON (((-2000238 15...8 0.6 3.22 MULTIPOLYGON (((708460.5 -5...9 0.5 2.89 MULTIPOLYGON (((122656.3 -1...10 0.0 1.26 MULTIPOLYGON (((-1226428 -5...
us_shp %>% left_join(WaPo_data, by=c("NAME" = "state")) %>% tigris::shift_geometry() -> # rescale AK, HI, PR us_shp2
tm_shape(us_shp2) + tm_polygons( )
tm_shape(us_shp2) + tm_polygons( col = "avgshare", palette = "Blues", )
tm_shape(us_shp2) + tm_polygons( col = "avgshare", palette = "Blues", border.col = "white", )
tm_shape(us_shp2) + tm_polygons( col = "avgshare", palette = "Blues", border.col = "white", ) + tm_text( text = "STUSPS", )
tm_shape(us_shp2) + tm_polygons( col = "avgshare", palette = "Blues", border.col = "white", ) + tm_text( text = "STUSPS", size = "avgshare", legend.size.show = FALSE )
tm_shape(us_shp2) + tm_polygons( col = "avgshare", palette = "Blues", border.col = "white", ) + tm_text( text = "STUSPS", size = "avgshare", legend.size.show = FALSE ) + tm_layout( frame = FALSE, )
tm_shape(us_shp2) + tm_polygons( col = "avgshare", palette = "Blues", border.col = "white", legend.is.portrait = FALSE, ) + tm_text( text = "STUSPS", size = "avgshare", legend.size.show = FALSE ) + tm_layout( frame = FALSE, legend.stack = "horizontal", )
tm_shape(us_shp2) + tm_polygons( col = "avgshare", palette = "Blues", border.col = "white", legend.is.portrait = FALSE, ) + tm_text( text = "STUSPS", size = "avgshare", legend.size.show = FALSE ) + tm_layout( frame = FALSE, legend.stack = "horizontal", legend.position = c('right', 'top'), )
tm_shape(us_shp2) + tm_polygons( col = "avgshare", palette = "Blues", border.col = "white", legend.is.portrait = FALSE, title = "Share of job loss due to trade", labels = c("Smallest", "", "", "Largest share") ) + tm_text( text = "STUSPS", size = "avgshare", legend.size.show = FALSE ) + tm_layout( frame = FALSE, legend.stack = "horizontal", legend.position = c('right', 'top'), legend.title.size = 1, legend.text.size = 0.5 )
tmap_save(tmap_object, filename = "[...].pdf")
Download the Rental Housing and Demographics in NYC data
Unzip it and put it in your working directory
Download the Rental Housing and Demographics in NYC data
Unzip it and put it in your working directory
# load .shp file with sfnyc_shp <- st_read("data/nyc/nyc.shp")
Reading layer `nyc' from data source `D:\Google Drive\Phd UW\Courses\5th year\CS&SS 569 - Visualizing Data and Models\Labs\Lab6\data\nyc\nyc.shp' using driver `ESRI Shapefile'Simple feature collection with 55 features and 34 fieldsGeometry type: MULTIPOLYGONDimension: XYBounding box: xmin: 913037.2 ymin: 120117 xmax: 1067549 ymax: 272751.4Projected CRS: NAD83 / New York Long Island (ftUS)
tm_shape(nyc_shp) + tm_polygons( )
tm_shape(nyc_shp) + tm_polygons( col = "rent2008", )
tm_shape(nyc_shp) + tm_polygons( col = "rent2008", palette = "BrBG", )
tm_shape(nyc_shp) + tm_polygons( col = "rent2008", palette = "BrBG", border.col = "white", )
tm_shape(nyc_shp) + tm_polygons( col = "rent2008", palette = "BrBG", border.col = "white", title = "Rent in 2008" )
tm_shape(nyc_shp) + tm_polygons( col = "rent2008", palette = "BrBG", border.col = "white", title = "Rent in 2008" ) + tm_layout(frame = FALSE)
## interactive mode in tmaptmap_mode("view")
## interactive mode in tmaptmap_mode("view")## switch off spherical geometry to avoid error## usually you don't need to do thissf::sf_use_s2(use_s2 = FALSE)
## interactive mode in tmaptmap_mode("view")## switch off spherical geometry to avoid error## usually you don't need to do thissf::sf_use_s2(use_s2 = FALSE)## tmaptm_shape(nyc_shp) + tm_polygons( col = "rent2008", palette = "BrBG", title = "Rent in 2008", alpha = 0.5 )
## interactive mode in tmaptmap_mode("view")## switch off spherical geometry to avoid error## usually you don't need to do thissf::sf_use_s2(use_s2 = FALSE)## tmaptm_shape(nyc_shp) + tm_polygons( col = "rent2008", palette = "BrBG", title = "Rent in 2008", alpha = 0.5 ) + tm_basemap( server = "OpenStreetMap", alpha = 0.5 )
## interactive mode in tmaptmap_mode("view")## switch off spherical geometry to avoid error## usually you don't need to do thissf::sf_use_s2(use_s2 = FALSE)## tmaptm_shape(nyc_shp) + tm_polygons( col = "rent2008", palette = "BrBG", title = "Rent in 2008", alpha = 0.5 ) + tm_basemap( server = "OpenStreetMap", alpha = 0.5 )## switch back to plotting modetmap_mode("plot")
tmap
? How to do small multiples in tmap
?
tmap_arrange()
: like cowplot::plot_grid()
; arrange multiple maps into a gridHow to do small multiples in tmap
?
tmap_arrange()
: like cowplot::plot_grid()
; arrange multiple maps into a grid
tm_facets()
: like facet_grid()
or facet_wrap()
; facet areas(polygons) by some variables
tm_shape(nyc_shp) + tm_polygons( col = "rent2008", palette = "BrBG", border.col = "white", title = "Rent in 2008" )
tm_shape(nyc_shp) + tm_polygons( col = "rent2008", palette = "BrBG", border.col = "white", title = "Rent in 2008" ) + tm_layout(frame = FALSE)
tm_shape(nyc_shp) + tm_polygons( col = "rent2008", palette = "BrBG", border.col = "white", title = "Rent in 2008" ) + tm_layout(frame = FALSE) -> rentNYC
tm_shape(nyc_shp) + tm_polygons( col = "forhis08", border.col = "white", title = "Hispanic population in 2008 (%)" )
tm_shape(nyc_shp) + tm_polygons( col = "forhis08", border.col = "white", title = "Hispanic population in 2008 (%)" ) + tm_layout(frame = FALSE)
tm_shape(nyc_shp) + tm_polygons( col = "forhis08", border.col = "white", title = "Hispanic population in 2008 (%)" ) + tm_layout(frame = FALSE) -> hisNYC
tm_shape(nyc_shp) + tm_polygons( col = "pubast00", palette = "Blues", border.col = "white", title = "% of households receiving \nassistance in 2000" )
tm_shape(nyc_shp) + tm_polygons( col = "pubast00", palette = "Blues", border.col = "white", title = "% of households receiving \nassistance in 2000" ) + tm_layout(frame = FALSE)
tm_shape(nyc_shp) + tm_polygons( col = "pubast00", palette = "Blues", border.col = "white", title = "% of households receiving \nassistance in 2000" ) + tm_layout(frame = FALSE) -> pubastNYC
tmap_arrange(rentNYC, hisNYC, pubastNYC, nrow = 1)
## categorize hispanic pop levelslabels <- c("Low hisp pop", "Mid hisp pop", "High hisp pop")
## categorize hispanic pop levelslabels <- c("Low hisp pop", "Mid hisp pop", "High hisp pop")nyc_shp
Simple feature collection with 55 features and 34 fieldsGeometry type: MULTIPOLYGONDimension: XYBounding box: xmin: 913037.2 ymin: 120117 xmax: 1067549 ymax: 272751.4Projected CRS: NAD83 / New York Long Island (ftUS)First 10 features: bor_subb name code subborough forhis061 501 North Shore 501 North Shore 37.06572 502 Mid-Island 502 Mid-Island 27.98223 503 South Shore 503 South Shore 10.70194 401 Astoria 401 Astoria 52.09615 402 Sunnyside / Woodside 402 Sunnyside/Woodside 62.72426 403 Jackson Heights 403 Jackson Heights 68.48347 404 Elmhurst / Corona 404 Elmhurst/Corona 69.52198 405 Middle Village / Ridgewood 405 Middle Village/Ridgewood 39.41859 406 Forest Hills / Rego Park 406 Rego Park/Forest Hills 58.538810 407 Flushing / Whitestone 407 Flushing/Whitestone 59.4432 forhis07 forhis08 forhis09 forwh06 forwh07 forwh08 forwh09 hhsiz1990 hhsiz001 34.0317 27.3767 29.3091 13.2540 11.8768 11.1788 11.1459 2.7146 2.73382 18.1193 24.0452 31.1566 20.0616 19.8575 22.4870 17.0371 2.8233 2.71763 12.1404 9.6890 14.6638 10.3060 12.7699 9.3561 10.2830 3.0547 2.84974 53.9585 54.6968 47.8050 38.3658 35.6551 32.1289 34.6578 2.4279 2.49955 69.3969 67.0897 58.2963 37.0512 31.9057 32.3264 33.8794 2.4646 2.62876 68.5405 66.5080 69.1580 34.3999 38.2428 38.1470 26.5347 2.8081 3.16507 66.8795 69.3414 64.3005 40.3935 51.6376 45.9578 48.3542 2.9690 3.17848 35.9546 36.2750 35.0181 37.8097 34.0156 33.0695 33.0816 2.5174 2.66069 52.6183 42.3878 47.9795 43.7395 47.5873 45.1205 39.8293 2.0631 2.153210 53.4747 53.2531 57.9868 26.5802 25.6864 21.3858 23.5204 2.6302 2.6818 hhsiz02 hhsiz05 hhsiz08 kids2000 kids2005 kids2006 kids2007 kids20081 2.7412 2.8010 2.6983 39.2995 43.3788 38.4022 41.5213 39.83902 2.5405 2.6228 2.5749 36.2234 35.7630 36.9081 37.6798 37.24473 2.6525 2.6121 2.6483 39.7362 42.5232 40.3577 40.3797 40.48204 2.3032 2.3227 2.2746 28.4592 27.2223 25.2556 24.8911 22.03645 2.5300 2.4993 2.4766 29.8808 28.6841 28.1440 26.3675 29.90326 2.9108 2.8599 2.8604 41.6335 40.2431 39.3135 37.4414 39.41447 2.8740 3.1064 3.2223 41.8224 35.8002 40.2321 44.0976 37.29128 2.7540 2.7750 2.7007 35.0385 36.6091 37.7748 37.6190 30.90969 2.1504 2.1932 2.1512 21.9464 21.4119 24.2723 23.7545 24.771810 2.5351 2.5668 2.5857 31.5298 27.7413 28.5853 28.1564 31.1019 kids2009 rent2002 rent2005 rent2008 rentpct02 rentpct05 rentpct08 pubast901 40.3169 800 900 1000 21.1119 24.8073 28.5344 47.329132 37.8176 650 800 950 32.3615 27.2584 27.9567 35.182323 35.3880 750 775 800 23.0547 20.4146 18.1590 23.894044 17.9996 1000 1100 1400 25.6022 26.7685 28.0467 80.533935 26.2156 1000 1000 1400 18.8079 22.6752 21.3009 75.516876 39.0377 910 1000 1100 34.0156 34.8050 27.1032 66.642287 43.3207 896 1001 1300 26.7381 34.3842 28.8255 77.530808 35.4524 800 900 1100 41.2035 40.6256 36.2956 59.017029 21.9552 1000 1035 1400 11.9766 10.4943 11.5520 64.1621310 28.3184 1000 1100 1200 23.9394 23.3487 22.6715 53.62965 pubast00 yrhom02 yrhom05 yrhom08 geometry1 6.005791 10.80507 12.127853 11.54743 MULTIPOLYGON (((962498.9 17...2 2.287034 15.24125 15.183111 14.68212 MULTIPOLYGON (((928296.9 16...3 1.350208 12.70425 12.972280 13.56149 MULTIPOLYGON (((932416.3 14...4 5.204510 12.83917 13.377513 12.54464 MULTIPOLYGON (((1010873 226...5 2.974139 15.38766 12.518789 12.66691 MULTIPOLYGON (((1011647 216...6 5.332569 12.64923 12.580355 11.96598 MULTIPOLYGON (((1014790 220...7 6.029230 11.55498 9.828084 10.73805 MULTIPOLYGON (((1018353 205...8 3.951290 13.49841 12.616178 11.19165 MULTIPOLYGON (((1013477 206...9 3.111417 13.40156 13.375477 12.74230 MULTIPOLYGON (((1026974 207...10 2.795721 14.01126 12.806067 12.84800 MULTIPOLYGON (((1034251 230...
## categorize hispanic pop levelslabels <- c("Low hisp pop", "Mid hisp pop", "High hisp pop")nyc_shp %>% mutate(forhis08_cat = cut(forhis08, breaks = 3, labels = labels))
Simple feature collection with 55 features and 35 fieldsGeometry type: MULTIPOLYGONDimension: XYBounding box: xmin: 913037.2 ymin: 120117 xmax: 1067549 ymax: 272751.4Projected CRS: NAD83 / New York Long Island (ftUS)First 10 features: bor_subb name code subborough forhis061 501 North Shore 501 North Shore 37.06572 502 Mid-Island 502 Mid-Island 27.98223 503 South Shore 503 South Shore 10.70194 401 Astoria 401 Astoria 52.09615 402 Sunnyside / Woodside 402 Sunnyside/Woodside 62.72426 403 Jackson Heights 403 Jackson Heights 68.48347 404 Elmhurst / Corona 404 Elmhurst/Corona 69.52198 405 Middle Village / Ridgewood 405 Middle Village/Ridgewood 39.41859 406 Forest Hills / Rego Park 406 Rego Park/Forest Hills 58.538810 407 Flushing / Whitestone 407 Flushing/Whitestone 59.4432 forhis07 forhis08 forhis09 forwh06 forwh07 forwh08 forwh09 hhsiz1990 hhsiz001 34.0317 27.3767 29.3091 13.2540 11.8768 11.1788 11.1459 2.7146 2.73382 18.1193 24.0452 31.1566 20.0616 19.8575 22.4870 17.0371 2.8233 2.71763 12.1404 9.6890 14.6638 10.3060 12.7699 9.3561 10.2830 3.0547 2.84974 53.9585 54.6968 47.8050 38.3658 35.6551 32.1289 34.6578 2.4279 2.49955 69.3969 67.0897 58.2963 37.0512 31.9057 32.3264 33.8794 2.4646 2.62876 68.5405 66.5080 69.1580 34.3999 38.2428 38.1470 26.5347 2.8081 3.16507 66.8795 69.3414 64.3005 40.3935 51.6376 45.9578 48.3542 2.9690 3.17848 35.9546 36.2750 35.0181 37.8097 34.0156 33.0695 33.0816 2.5174 2.66069 52.6183 42.3878 47.9795 43.7395 47.5873 45.1205 39.8293 2.0631 2.153210 53.4747 53.2531 57.9868 26.5802 25.6864 21.3858 23.5204 2.6302 2.6818 hhsiz02 hhsiz05 hhsiz08 kids2000 kids2005 kids2006 kids2007 kids20081 2.7412 2.8010 2.6983 39.2995 43.3788 38.4022 41.5213 39.83902 2.5405 2.6228 2.5749 36.2234 35.7630 36.9081 37.6798 37.24473 2.6525 2.6121 2.6483 39.7362 42.5232 40.3577 40.3797 40.48204 2.3032 2.3227 2.2746 28.4592 27.2223 25.2556 24.8911 22.03645 2.5300 2.4993 2.4766 29.8808 28.6841 28.1440 26.3675 29.90326 2.9108 2.8599 2.8604 41.6335 40.2431 39.3135 37.4414 39.41447 2.8740 3.1064 3.2223 41.8224 35.8002 40.2321 44.0976 37.29128 2.7540 2.7750 2.7007 35.0385 36.6091 37.7748 37.6190 30.90969 2.1504 2.1932 2.1512 21.9464 21.4119 24.2723 23.7545 24.771810 2.5351 2.5668 2.5857 31.5298 27.7413 28.5853 28.1564 31.1019 kids2009 rent2002 rent2005 rent2008 rentpct02 rentpct05 rentpct08 pubast901 40.3169 800 900 1000 21.1119 24.8073 28.5344 47.329132 37.8176 650 800 950 32.3615 27.2584 27.9567 35.182323 35.3880 750 775 800 23.0547 20.4146 18.1590 23.894044 17.9996 1000 1100 1400 25.6022 26.7685 28.0467 80.533935 26.2156 1000 1000 1400 18.8079 22.6752 21.3009 75.516876 39.0377 910 1000 1100 34.0156 34.8050 27.1032 66.642287 43.3207 896 1001 1300 26.7381 34.3842 28.8255 77.530808 35.4524 800 900 1100 41.2035 40.6256 36.2956 59.017029 21.9552 1000 1035 1400 11.9766 10.4943 11.5520 64.1621310 28.3184 1000 1100 1200 23.9394 23.3487 22.6715 53.62965 pubast00 yrhom02 yrhom05 yrhom08 geometry1 6.005791 10.80507 12.127853 11.54743 MULTIPOLYGON (((962498.9 17...2 2.287034 15.24125 15.183111 14.68212 MULTIPOLYGON (((928296.9 16...3 1.350208 12.70425 12.972280 13.56149 MULTIPOLYGON (((932416.3 14...4 5.204510 12.83917 13.377513 12.54464 MULTIPOLYGON (((1010873 226...5 2.974139 15.38766 12.518789 12.66691 MULTIPOLYGON (((1011647 216...6 5.332569 12.64923 12.580355 11.96598 MULTIPOLYGON (((1014790 220...7 6.029230 11.55498 9.828084 10.73805 MULTIPOLYGON (((1018353 205...8 3.951290 13.49841 12.616178 11.19165 MULTIPOLYGON (((1013477 206...9 3.111417 13.40156 13.375477 12.74230 MULTIPOLYGON (((1026974 207...10 2.795721 14.01126 12.806067 12.84800 MULTIPOLYGON (((1034251 230... forhis08_cat1 Low hisp pop2 Low hisp pop3 Low hisp pop4 High hisp pop5 High hisp pop6 High hisp pop7 High hisp pop8 Mid hisp pop9 Mid hisp pop10 High hisp pop
## categorize hispanic pop levelslabels <- c("Low hisp pop", "Mid hisp pop", "High hisp pop")nyc_shp %>% mutate(forhis08_cat = cut(forhis08, breaks = 3, labels = labels)) -> nyc_shp2
tm_shape(nyc_shp2) + tm_polygons( col = "rent2008", palette = "BrBG", border.col = "white", title = "Rent in 2008" )
tm_shape(nyc_shp2) + tm_polygons( col = "rent2008", palette = "BrBG", border.col = "white", title = "Rent in 2008" ) + tm_facets( by = "forhis08_cat", drop.units = TRUE, )
tm_shape(nyc_shp2) + tm_polygons( col = "rent2008", palette = "BrBG", border.col = "white", title = "Rent in 2008" ) + tm_facets( by = "forhis08_cat", drop.units = TRUE, free.coords = FALSE, )
tm_shape(nyc_shp2) + tm_polygons( col = "rent2008", palette = "BrBG", border.col = "white", title = "Rent in 2008" ) + tm_facets( by = "forhis08_cat", drop.units = TRUE, free.coords = FALSE, ) + tm_layout( legend.outside.size = 0.135, )
tm_shape(nyc_shp2) + tm_polygons( col = "rent2008", palette = "BrBG", border.col = "white", title = "Rent in 2008" ) + tm_facets( by = "forhis08_cat", drop.units = TRUE, free.coords = FALSE, ) + tm_layout( legend.outside.size = 0.135, frame = FALSE, )
tm_shape(nyc_shp2) + tm_polygons( col = "rent2008", palette = "BrBG", border.col = "white", title = "Rent in 2008" ) + tm_facets( by = "forhis08_cat", drop.units = TRUE, free.coords = FALSE, ) + tm_layout( legend.outside.size = 0.135, frame = FALSE, panel.label.bg.color = NA, )
tm_shape(nyc_shp2) + tm_polygons( col = "rent2008", palette = "BrBG", border.col = "white", title = "Rent in 2008" ) + tm_facets( by = "forhis08_cat", drop.units = TRUE, free.coords = FALSE, ) + tm_layout( legend.outside.size = 0.135, frame = FALSE, panel.label.bg.color = NA, frame.lwd = 0, )
tm_shape(nyc_shp2) + tm_polygons( col = "rent2008", palette = "BrBG", border.col = "white", title = "Rent in 2008" ) + tm_facets( by = "forhis08_cat", drop.units = TRUE, free.coords = FALSE, ) + tm_layout( legend.outside.size = 0.135, frame = FALSE, panel.label.bg.color = NA, frame.lwd = 0, panel.label.size = 1.5 )
tm_shape(nyc_shp2) + tm_polygons( col = "rent2008", palette = "BrBG", border.col = "white", title = "Rent in 2008" ) + tm_facets( by = "forhis08_cat", drop.units = TRUE, free.coords = FALSE, ) + tm_layout( legend.outside.size = 0.135, frame = FALSE, panel.label.bg.color = NA, frame.lwd = 0, panel.label.size = 1.5 ) + tm_shape(nyc_shp2) + tm_borders(col = "grey75", lty = 2)
Keyboard shortcuts
↑, ←, Pg Up, k | Go to previous slide |
↓, →, Pg Dn, Space, j | Go to next slide |
Home | Go to first slide |
End | Go to last slide |
Number + Return | Go to specific slide |
b / m / f | Toggle blackout / mirrored / fullscreen mode |
c | Clone slideshow |
p | Toggle presenter mode |
t | Restart the presentation timer |
?, h | Toggle this help |
Esc | Back to slideshow |