repository for geography work and other things completed by kufre u.
library(tidyverse)
library(sf)
library(sp)
library(geosphere)
library(viridis)
library(viridisLite)
#### loading data ####
# data was in same folder as r project
tractsMI <- st_read(dsn = "censusMI.gpkg", layer = "tracts")
chicago <- st_read(dsn = "chicago.gpkg", layer = "tracts2010")
chicagoCBD <- st_read(dsn = "chicago.gpkg", layer = "CBD")
#### getting counties & tracts ####
tracts2 <- tractsMI %>%
# making factors characters to make them easier to work with
mutate(fips = as.character(COUNTYFP))
# counties divided into tracts
delta <- tracts2[tracts2$fips == "041", ]
berrien <- tracts2[tracts2$fips == "021", ]
gogebic <- tracts2[tracts2$fips == "053", ]
ontonagon <- tracts2[tracts2$fips == "131", ]
charlevoix <- tracts2[tracts2$fips == "029", ]
alger <- tracts2[tracts2$fips == "003", ]
washtenaw <- tracts2[tracts2$fips == "161", ]
keweenaw <- tracts2[tracts2$fips == "083", ]
# undivided counties
countiesMI <- tracts2 %>%
group_by(fips) %>%
summarize
delta <- countiesMI[countiesMI$fips == "041", ]
berrien <- countiesMI[countiesMI$fips == "021", ]
gogebic <- countiesMI[countiesMI$fips == "053", ]
ontonagon <- countiesMI[countiesMI$fips == "131", ]
charlevoix <- countiesMI[countiesMI$fips == "029", ]
alger <- countiesMI[countiesMI$fips == "003", ]
washtenaw <- countiesMI[countiesMI$fips == "161", ]
keweenaw <- countiesMI[countiesMI$fips == "083", ]
These maps were made with the distdir_from_point
function that had layer and center as arguments rather than input and origin.
distdir_from_point(center = berrien,
layer = countiesMI,
prefix = "ber") %>%
mutate("Distance (km)" = ber_dist_double / 1000) %>%
ggplot() +
geom_sf(aes(fill = `Distance (km)`),
color = "white") +
scale_fill_viridis() +
labs(title = "Distance from Berrien County")
distdir_from_point(center = gogebic,
layer = tractsMI,) %>%
mutate("Distance (km)" = dist_double / 1000) %>%
ggplot() +
geom_sf(aes(fill = `Distance (km)`),
color = NA) +
scale_fill_viridis() +
labs(title = "Distance of Census Tracts from Gogebic County",
x = "Longitude",
y = "Latitude")
distdir_from_point(center = berrien,
layer = tractsMI,
prefix = "ber") %>%
mutate("Distance (km)" = ber_dist_double / 1000) %>%
filter(ber_card_ord == "N") %>%
ggplot() +
geom_sf(aes(fill = `Distance (km)`),
color = NA) +
scale_fill_viridis() +
labs(title = "Census Tracts North of Berrien County",
x = "Longitude",
y = "Latitude")
distdir_from_point(center = washtenaw,
layer = tractsMI,
prefix = "wa") %>%
mutate("Distance (km)" = cbd_dist_double / 1000) %>%
filter(wa_card_ord == "NW") %>%
ggplot() +
geom_sf(aes(fill = `Distance (km)`),
color = NA) +
scale_fill_viridis() +
labs(title = "Census Tracts Northwest of Washtenaw County")
distdir_from_point(center = berrien,
layer = tractsMI,
prefix = "ber") %>%
mutate("Distance (km)" = ber_dist_double / 1000) %>%
filter(ber_card_ord == "NE" & `Distance (km)` >= 200) %>%
ggplot() +
geom_sf(aes(fill = `Distance (km)`),
color = NA) +
scale_fill_viridis() +
labs(title = "Census Tracts Northeast of Berrien County and >= 200km")
distdir_from_point(center = chicagoCBD,
layer = chicago,
prefix = "cbd") %>%
mutate("Distance (km)" = cbd_dist_double / 1000) %>%
ggplot() +
geom_sf(aes(fill = `Distance (km)`),
color = NA) +
scale_fill_viridis() +
labs(title = "Distance of Tracts from the CBD of Chicago")
data sources: U.S. Census Bureau; 2018 Census Tracts for Michigan, 2017 American Community Survey 5-Year Estimates, Tables B25064 and B03002
data source: Census, though otherwise unknown