# Loading and Installing all Necessary Packages
library(flexdashboard)
library(tidyverse)
Registered S3 methods overwritten by 'dbplyr':
method from
print.tbl_lazy
print.tbl_sql
── Attaching packages ──────────────────────────────────────────────────────────────────────────────────────────── tidyverse 1.3.2 ──✔ ggplot2 3.4.2 ✔ purrr 1.0.1
✔ tibble 3.2.1 ✔ dplyr 1.1.1
✔ tidyr 1.3.0 ✔ stringr 1.5.0
✔ readr 2.1.3 ✔ forcats 0.5.2── Conflicts ─────────────────────────────────────────────────────────────────────────────────────────────── tidyverse_conflicts() ──
✖ tidyr::extract() masks raster::extract()
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
✖ dplyr::select() masks raster::select()
library(sf)
Linking to GEOS 3.10.2, GDAL 3.4.2, PROJ 8.2.1; sf_use_s2() is TRUE
library(lubridate)
Attaching package: ‘lubridate’
The following objects are masked from ‘package:raster’:
intersect, union
The following objects are masked from ‘package:base’:
date, intersect, setdiff, union
library(jsonlite)
Attaching package: ‘jsonlite’
The following object is masked from ‘package:purrr’:
flatten
library(plotly)
Attaching package: ‘plotly’
The following object is masked from ‘package:ggplot2’:
last_plot
The following object is masked from ‘package:raster’:
select
The following object is masked from ‘package:stats’:
filter
The following object is masked from ‘package:graphics’:
layout
library(hablar)
Attaching package: ‘hablar’
The following object is masked from ‘package:forcats’:
fct
The following object is masked from ‘package:dplyr’:
na_if
The following object is masked from ‘package:tibble’:
num
library(RColorBrewer)
# devtools::install_github("hadley/emo")
library(emo)
library(tmap)
library(rsconnect)
library(ggplot2)
install.packages("tidycensus")
trying URL 'https://cran.rstudio.com/bin/macosx/contrib/4.2/tidycensus_1.3.2.tgz'
Content type 'application/x-gzip' length 3254143 bytes (3.1 MB)
==================================================
downloaded 3.1 MB
The downloaded binary packages are in
/var/folders/3c/_nnr32td5vj918mbvndpd3fw0000gn/T//Rtmpday0Nj/downloaded_packages
library(tidycensus)
install.packages('gganimate')
trying URL 'https://cran.rstudio.com/bin/macosx/contrib/4.2/gganimate_1.0.8.tgz'
Content type 'application/x-gzip' length 1294329 bytes (1.2 MB)
==================================================
downloaded 1.2 MB
The downloaded binary packages are in
/var/folders/3c/_nnr32td5vj918mbvndpd3fw0000gn/T//Rtmpday0Nj/downloaded_packages
library(gganimate)
Attaching package: ‘gganimate’
The following object is masked from ‘package:raster’:
animate
#install.packages("transformr")
library(transformr)
Attaching package: ‘transformr’
The following object is masked from ‘package:sf’:
st_normalize
In the following section, I manipulate and map population data provided by the American Community Survey. It is important to note that the data selected is for Wayne County, where the city of Detroit resides. The reasoning for this is twofold: 1. It was easier to download tract level data for the entire county. 2. I believe that mapping that illustrates changes in population of one specific region (in this case the city of Detroit) should include the surrounding area. Perhaps this mapping will find that as people move in or out of Detroit, the rest of Wayne County may have the opposite reaction (i.e., people moving from the city center to the suburbs, etc.)
# Downloading population data from TidyCensus for mapping. Population is one of they key factors looked into for this research project, as it marks the influx/exodus of people in Detroit. I limited my time period to 2010-2021, as I wanted to see changes in the Detroit area in the most recent decade.
pop21 <- get_acs(geography = "tract", variables = "B01003_001",
state = "MI", county = "Wayne", geometry = TRUE, year = 2021)
Getting data from the 2017-2021 5-year ACS
Warning: • You have not set a Census API key. Users without a key are limited to 500
queries per day and may experience performance limitations.
ℹ For best results, get a Census API key at
http://api.census.gov/data/key_signup.html and then supply the key to the
`census_api_key()` function to use it throughout your tidycensus session.Downloading feature geometry from the Census website. To cache shapefiles for use in future sessions, set `options(tigris_use_cache = TRUE)`.
Using FIPS code '26' for state 'MI'
Using FIPS code '163' for 'Wayne County'
|
| | 0%
|
|= | 1%
|
|== | 1%
|
|== | 2%
|
|=== | 2%
|
|=== | 3%
|
|==== | 3%
|
|===== | 4%
|
|====== | 5%
|
|======== | 6%
|
|======== | 7%
|
|========= | 7%
|
|========= | 8%
|
|=========== | 9%
|
|============= | 11%
|
|=============== | 12%
|
|================ | 13%
|
|================= | 14%
|
|================== | 15%
|
|==================== | 17%
|
|===================== | 17%
|
|======================= | 19%
|
|========================= | 21%
|
|============================ | 22%
|
|============================== | 24%
|
|============================== | 25%
|
|================================ | 26%
|
|================================= | 27%
|
|=================================== | 28%
|
|====================================== | 31%
|
|========================================= | 33%
|
|========================================== | 34%
|
|============================================ | 35%
|
|============================================ | 36%
|
|=============================================== | 38%
|
|================================================= | 40%
|
|================================================== | 41%
|
|====================================================== | 44%
|
|========================================================== | 47%
|
|============================================================ | 49%
|
|============================================================= | 49%
|
|=================================================================== | 55%
|
|==================================================================== | 55%
|
|========================================================================= | 60%
|
|============================================================================== | 64%
|
|================================================================================== | 67%
|
|======================================================================================= | 71%
|
|======================================================================================== | 71%
|
|============================================================================================= | 76%
|
|=================================================================================================== | 80%
|
|========================================================================================================== | 86%
|
|============================================================================================================ | 88%
|
|============================================================================================================== | 89%
|
|==================================================================================================================== | 94%
|
|========================================================================================================================== | 100%
|
|===========================================================================================================================| 100%
pop20 <- get_acs(geography = "tract", variables = "B01003_001",
state = "MI", county = "Wayne", geometry = TRUE, year = 2020)
Getting data from the 2016-2020 5-year ACS
Downloading feature geometry from the Census website. To cache shapefiles for use in future sessions, set `options(tigris_use_cache = TRUE)`.
Using FIPS code '26' for state 'MI'
Using FIPS code '163' for 'Wayne County'
|
| | 0%
|
|======== | 7%
|
|================ | 13%
|
|========================== | 21%
|
|==================================== | 30%
|
|====================================================== | 44%
|
|============================================================================ | 62%
|
|=================================================================================================== | 80%
|
|======================================================================================================== | 84%
|
|======================================================================================================== | 85%
|
|========================================================================================================== | 86%
|
|================================================================================================================ | 91%
|
|===========================================================================================================================| 100%
pop19 <- get_acs(geography = "tract", variables = "B01003_001",
state = "MI", county = "Wayne", geometry = TRUE, year = 2019)
Getting data from the 2015-2019 5-year ACS
Downloading feature geometry from the Census website. To cache shapefiles for use in future sessions, set `options(tigris_use_cache = TRUE)`.
Using FIPS code '26' for state 'MI'
Using FIPS code '163' for 'Wayne County'
|
| | 0%
|
|======== | 6%
|
|================= | 14%
|
|=========================== | 22%
|
|=============================================== | 38%
|
|================================================ | 39%
|
|================================================== | 41%
|
|======================================================= | 45%
|
|========================================================== | 47%
|
|============================================================================= | 62%
|
|=================================================================================================================== | 93%
|
|===========================================================================================================================| 100%
pop18 <- get_acs(geography = "tract", variables = "B01003_001",
state = "MI", county = "Wayne", geometry = TRUE, year = 2018)
Getting data from the 2014-2018 5-year ACS
Downloading feature geometry from the Census website. To cache shapefiles for use in future sessions, set `options(tigris_use_cache = TRUE)`.
Using FIPS code '26' for state 'MI'
Using FIPS code '163' for 'Wayne County'
|
| | 0%
|
|=== | 2%
|
|===== | 4%
|
|======= | 6%
|
|=========== | 9%
|
|================ | 13%
|
|====================== | 18%
|
|==================================================== | 43%
|
|========================================================================================== | 73%
|
|===========================================================================================================================| 100%
pop17 <- get_acs(geography = "tract", variables = "B01003_001",
state = "MI", county = "Wayne", geometry = TRUE, year = 2017)
Getting data from the 2013-2017 5-year ACS
Downloading feature geometry from the Census website. To cache shapefiles for use in future sessions, set `options(tigris_use_cache = TRUE)`.
Using FIPS code '26' for state 'MI'
Using FIPS code '163' for 'Wayne County'
|
| | 0%
|
|=== | 2%
|
|======= | 6%
|
|=========== | 9%
|
|============= | 11%
|
|================ | 13%
|
|==================== | 16%
|
|================================== | 27%
|
|============================================= | 36%
|
|====================================================== | 44%
|
|============================================================================= | 62%
|
|======================================================================================================== | 85%
|
|===========================================================================================================================| 100%
pop16 <- get_acs(geography = "tract", variables = "B01003_001",
state = "MI", county = "Wayne", geometry = TRUE, year = 2016)
Getting data from the 2012-2016 5-year ACS
Downloading feature geometry from the Census website. To cache shapefiles for use in future sessions, set `options(tigris_use_cache = TRUE)`.
Using FIPS code '26' for state 'MI'
Using FIPS code '163' for 'Wayne County'
|
| | 0%
|
|=========== | 9%
|
|================================================== | 40%
|
|======================================================================================== | 71%
|
|===========================================================================================================================| 100%
pop15 <- get_acs(geography = "tract", variables = "B01003_001",
state = "MI", county = "Wayne", geometry = TRUE, year = 2015)
Getting data from the 2011-2015 5-year ACS
Downloading feature geometry from the Census website. To cache shapefiles for use in future sessions, set `options(tigris_use_cache = TRUE)`.
Using FIPS code '26' for state 'MI'
Using FIPS code '163' for 'Wayne County'
|
| | 0%
|
|== | 2%
|
|===== | 4%
|
|============== | 12%
|
|==================================================== | 42%
|
|=========================================================================================== | 74%
|
|===========================================================================================================================| 100%
pop14 <- get_acs(geography = "tract", variables = "B01003_001",
state = "MI", county = "Wayne", geometry = TRUE, year = 2014)
Getting data from the 2010-2014 5-year ACS
Downloading feature geometry from the Census website. To cache shapefiles for use in future sessions, set `options(tigris_use_cache = TRUE)`.
Using FIPS code '26' for state 'MI'
Using FIPS code '163' for 'Wayne County'
|
| | 0%
|
|======== | 7%
|
|================= | 14%
|
|====================== | 18%
|
|======================== | 19%
|
|========================== | 21%
|
|================================ | 26%
|
|================================= | 27%
|
|================================================== | 40%
|
|======================================================================= | 57%
|
|============================================================================================== | 77%
|
|===========================================================================================================================| 100%
pop13 <- get_acs(geography = "tract", variables = "B01003_001",
state = "MI", county = "Wayne", geometry = TRUE, year = 2013)
Getting data from the 2009-2013 5-year ACS
Downloading feature geometry from the Census website. To cache shapefiles for use in future sessions, set `options(tigris_use_cache = TRUE)`.
Using FIPS code '26' for state 'MI'
Using FIPS code '163' for 'Wayne County'
|
| | 0%
|
|== | 2%
|
|============= | 11%
|
|=================== | 15%
|
|============================================================= | 50%
|
|============================================================================= | 62%
|
|=============================================================================== | 64%
|
|============================================================================================== | 77%
|
|================================================================================================================== | 93%
|
|====================================================================================================================== | 96%
|
|===========================================================================================================================| 100%
pop12 <- get_acs(geography = "tract", variables = "B01003_001",
state = "MI", county = "Wayne", geometry = TRUE, year = 2012)
Getting data from the 2008-2012 5-year ACS
Downloading feature geometry from the Census website. To cache shapefiles for use in future sessions, set `options(tigris_use_cache = TRUE)`.
Using FIPS code '26' for state 'MI'
Using FIPS code '163' for 'Wayne County'
|
| | 0%
|
|= | 1%
|
|== | 1%
|
|=== | 3%
|
|====== | 5%
|
|========= | 7%
|
|============= | 11%
|
|====================== | 18%
|
|================================ | 26%
|
|========================================== | 34%
|
|================================================== | 41%
|
|========================================================= | 47%
|
|=========================================================== | 48%
|
|============================================================ | 48%
|
|================================================================== | 54%
|
|====================================================================== | 57%
|
|======================================================================= | 58%
|
|======================================================================== | 59%
|
|========================================================================== | 60%
|
|=================================================================================== | 68%
|
|===================================================================================== | 69%
|
|========================================================================================== | 73%
|
|=============================================================================================== | 77%
|
|====================================================================================================== | 83%
|
|========================================================================================================== | 86%
|
|============================================================================================================== | 89%
|
|=============================================================================================================== | 90%
|
|===================================================================================================================== | 95%
|
|===========================================================================================================================| 100%
pop11 <- get_acs(geography = "tract", variables = "B01003_001",
state = "MI", county = "Wayne", geometry = TRUE, year = 2011)
Getting data from the 2007-2011 5-year ACS
Downloading feature geometry from the Census website. To cache shapefiles for use in future sessions, set `options(tigris_use_cache = TRUE)`.
Using FIPS code '26' for state 'MI'
Using FIPS code '163' for 'Wayne County'
|
| | 0%
|
|= | 1%
|
|=== | 3%
|
|===== | 4%
|
|=============== | 13%
|
|========================== | 21%
|
|===================================== | 30%
|
|========================================= | 33%
|
|========================================= | 34%
|
|============================================= | 37%
|
|============================================== | 38%
|
|================================================= | 40%
|
|================================================== | 41%
|
|===================================================== | 43%
|
|========================================================== | 47%
|
|===================================================================== | 56%
|
|================================================================================ | 65%
|
|=========================================================================================== | 74%
|
|==================================================================================================== | 82%
|
|======================================================================================================= | 84%
|
|================================================================================================================= | 92%
|
|===========================================================================================================================| 100%
pop10 <- get_acs(geography = "tract", variables = "B01003_001",
state = "MI", county = "Wayne", geometry = TRUE, year = 2010)
Getting data from the 2006-2010 5-year ACS
Downloading feature geometry from the Census website. To cache shapefiles for use in future sessions, set `options(tigris_use_cache = TRUE)`.
Using FIPS code '26' for state 'MI'
Using FIPS code '163' for 'Wayne County'
|
| | 0%
|
|====== | 5%
|
|======== | 6%
|
|========= | 8%
|
|========== | 8%
|
|================================================= | 40%
|
|======================================================= | 44%
|
|=============================================================== | 51%
|
|================================================================================= | 66%
|
|====================================================================================== | 70%
|
|===================================================================================================== | 82%
|
|========================================================================================================== | 86%
|
|================================================================================================================== | 93%
|
|========================================================================================================================== | 99%
|
|===========================================================================================================================| 100%
# This data is pulled from the American Community Survey (ACS) and uses the 1-year estimate. This means that this data has a margin of error.
# Tidying my data
stastibble <- function(pop){as_tibble(pop)}
pop21_tibble <- stastibble(pop21)
pop20_tibble <- stastibble(pop20)
pop19_tibble <- stastibble(pop19)
pop18_tibble <- stastibble(pop18)
pop17_tibble <- stastibble(pop17)
pop16_tibble <- stastibble(pop16)
pop15_tibble <- stastibble(pop15)
pop14_tibble <- stastibble(pop14)
pop13_tibble <- stastibble(pop13)
pop12_tibble <- stastibble(pop12)
pop11_tibble <- stastibble(pop11)
pop10_tibble <- stastibble(pop10)
# Joining the data, making one dataframe with all of the years collected (2010 - 2021)
pop_joined <- left_join(pop21_tibble, pop20_tibble %>% dplyr::select(estimate, GEOID), by = 'GEOID')
pop_joined <- left_join(pop_joined, pop19_tibble %>% dplyr::select(estimate, GEOID), by = 'GEOID')
pop_joined <- left_join(pop_joined, pop18_tibble %>% dplyr::select(estimate, GEOID), by = 'GEOID')
pop_joined <- left_join(pop_joined, pop17_tibble %>% dplyr::select(estimate, GEOID), by = 'GEOID')
pop_joined <- left_join(pop_joined, pop16_tibble %>% dplyr::select(estimate, GEOID), by = 'GEOID')
pop_joined <- left_join(pop_joined, pop15_tibble %>% dplyr::select(estimate, GEOID), by = 'GEOID')
pop_joined <- left_join(pop_joined, pop14_tibble %>% dplyr::select(estimate, GEOID), by = 'GEOID')
pop_joined <- left_join(pop_joined, pop13_tibble %>% dplyr::select(estimate, GEOID), by = 'GEOID')
pop_joined <- left_join(pop_joined, pop12_tibble %>% dplyr::select(estimate, GEOID), by = 'GEOID')
pop_joined <- left_join(pop_joined, pop11_tibble %>% dplyr::select(estimate, GEOID), by = 'GEOID')
pop_joined <- left_join(pop_joined, pop10_tibble %>% dplyr::select(estimate, GEOID), by = 'GEOID')
# Transforming my data into an object with geographical/spatial information (an SF object)
pop_joined <- drop_na(pop_joined)
pop_joined_sf <- st_as_sf(pop_joined, sf_column_name = 'geometry', crs = 4326)
Warning: st_crs<- : replacing crs does not reproject data; use st_transform for that
# Renaming columns
colnames(pop_joined_sf)[4] = "estimate21"
colnames(pop_joined_sf)[7] = "estimate20"
colnames(pop_joined_sf)[8] = "estimate19"
colnames(pop_joined_sf)[9] = "estimate18"
colnames(pop_joined_sf)[10] = "estimate17"
colnames(pop_joined_sf)[11] = "estimate16"
colnames(pop_joined_sf)[12] = "estimate15"
colnames(pop_joined_sf)[13] = "estimate14"
colnames(pop_joined_sf)[14] = "estimate13"
colnames(pop_joined_sf)[15] = "estimate12"
colnames(pop_joined_sf)[16] = "estimate11"
colnames(pop_joined_sf)[17] = "estimate10"
str(pop_joined_sf)
sf [520 × 17] (S3: sf/tbl_df/tbl/data.frame)
$ GEOID : chr [1:520] "26163563900" "26163542400" "26163542300" "26163517000" ...
$ NAME : chr [1:520] "Census Tract 5639, Wayne County, Michigan" "Census Tract 5424, Wayne County, Michigan" "Census Tract 5423, Wayne County, Michigan" "Census Tract 5170, Wayne County, Michigan" ...
$ variable : chr [1:520] "B01003_001" "B01003_001" "B01003_001" "B01003_001" ...
$ estimate21: num [1:520] 2605 2587 2671 2905 2078 ...
$ moe : num [1:520] 428 297 671 403 252 755 464 488 860 554 ...
$ geometry :sfc_MULTIPOLYGON of length 520; first list element: List of 1
..$ :List of 1
.. ..$ : num [1:9, 1:2] -83.5 -83.5 -83.5 -83.4 -83.4 ...
..- attr(*, "class")= chr [1:3] "XY" "MULTIPOLYGON" "sfg"
$ estimate20: num [1:520] 2528 2340 2473 3261 2016 ...
$ estimate19: num [1:520] 2315 2763 1989 3111 1963 ...
$ estimate18: num [1:520] 2343 2709 1887 3359 2062 ...
$ estimate17: num [1:520] 2339 2511 1869 3450 1994 ...
$ estimate16: num [1:520] 2312 2320 1814 3268 1650 ...
$ estimate15: num [1:520] 2368 2235 1838 2995 1649 ...
$ estimate14: num [1:520] 2392 2393 2175 2788 1701 ...
$ estimate13: num [1:520] 2412 2550 2130 2507 1468 ...
$ estimate12: num [1:520] 2478 2515 2177 2354 1570 ...
$ estimate11: num [1:520] 2585 2592 2343 2218 1545 ...
$ estimate10: num [1:520] 2479 2828 2459 2341 1739 ...
- attr(*, "sf_column")= chr "geometry"
- attr(*, "agr")= Factor w/ 3 levels "constant","aggregate",..: NA NA NA NA NA NA NA NA NA NA ...
..- attr(*, "names")= chr [1:16] "GEOID" "NAME" "variable" "estimate.x" ...
# Making a static map first to test out aesthetics
detroit_map_population <- ggplot() + geom_sf(data = pop_joined_sf, color = "black", aes(fill = estimate21)) + theme_light(base_size = 10) + scale_fill_gradient(low = "lightblue1", high = "indianred4")
detroit_map_population
# to utilize the gganimate package, you have to turn you data from wide format to long format
pop_joined_Sf_long <- pivot_longer(data = pop_joined_sf, cols =c(estimate21, estimate20:estimate10))
# remapping my data that is now in long format
pop_joined_Sf_long %>% group_by(name)
Simple feature collection with 6240 features and 6 fields
Geometry type: MULTIPOLYGON
Dimension: XY
Bounding box: xmin: -83.55191 ymin: 42.03334 xmax: -82.86942 ymax: 42.45101
Geodetic CRS: WGS 84
detroit_map_pop_forgif <- ggplot() + geom_sf(data = pop_joined_Sf_long, color = "black", aes(fill = value)) + theme_light(base_size = 10) + scale_fill_gradient(low = "lightblue1", high = "indianred4")
detroit_map_pop_forgif
# Renaming columns
pop_joined_Sf_long$name[pop_joined_Sf_long$name == 'estimate21'] <- '2021'
pop_joined_Sf_long$name[pop_joined_Sf_long$name == 'estimate20'] <- '2020'
pop_joined_Sf_long$name[pop_joined_Sf_long$name == 'estimate19'] <- '2019'
pop_joined_Sf_long$name[pop_joined_Sf_long$name == 'estimate18'] <- '2018'
pop_joined_Sf_long$name[pop_joined_Sf_long$name == 'estimate17'] <- '2017'
pop_joined_Sf_long$name[pop_joined_Sf_long$name == 'estimate16'] <- '2016'
pop_joined_Sf_long$name[pop_joined_Sf_long$name == 'estimate15'] <- '2015'
pop_joined_Sf_long$name[pop_joined_Sf_long$name == 'estimate14'] <- '2014'
pop_joined_Sf_long$name[pop_joined_Sf_long$name == 'estimate13'] <- '2013'
pop_joined_Sf_long$name[pop_joined_Sf_long$name == 'estimate12'] <- '2012'
pop_joined_Sf_long$name[pop_joined_Sf_long$name == 'estimate11'] <- '2011'
pop_joined_Sf_long$name[pop_joined_Sf_long$name == 'estimate10'] <- '2010'
# Transforming the year column from character vectors to integers
colnames(pop_joined_Sf_long)[6] <- 'year'
pop_joined_Sf_long$year <- as.integer(pop_joined_Sf_long$year)
# Creating the gif of the population map using gganimate package
detroit_map_pop_gif <- ggplot() + geom_sf(data = pop_joined_Sf_long, color = "black", aes(fill = value)) + theme_light(base_size = 10) + scale_fill_gradient(low = "lightblue1", high = "indianred4") + transition_time(year) + labs(title = "Population by Census Tract by Year: {frame_time}")
detroit_map_pop_gif
In the following section, I will map changes in vacancies in Detroit in the 2010s and early 2020s.
detroit_vacancies <- read_csv("detroitvac.characteristics.compiled - Sheet1 (2).csv")
Rows: 11 Columns: 9── Column specification ─────────────────────────────────────────────────────────────────────────────────
Delimiter: ","
dbl (2): Year, For migrant workers
num (7): Total, For rent, Rented, not occupied, For sale only, Sold, not occupied, For seasonal, recr...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
detroit_vacancies$`Rented, not occupied`<- as.integer(detroit_vacancies$`Rented, not occupied`)
detroit_line_graph_vacancies_1 <- ggplot() + geom_point(data = detroit_vacancies, aes(x = Year, y= `Rented, not occupied`)) + transition_time(Year) + labs(title = "Rented, not Occupied Vacancies in Detroit by Year: {frame_time}")
detroit_line_graph_vacancies_1
detroit_line_graph_vacancies_2 <- ggplot() + geom_point(data = detroit_vacancies, aes(x = Year, y= `Sold, not occupied`)) + transition_time(Year) + labs(title = "Sold, not Occupied Vacancies in Detroit by Year: {frame_time}")
detroit_line_graph_vacancies_2
stastibble <- function(vacancy){as_tibble(vacancy)}
vacancy_tract_21_tibble <- stastibble(vacancy_tract_21)
vacancy_tract_20_tibble <- stastibble(vacancy_tract_20)
vacancy_tract_19_tibble <- stastibble(vacancy_tract_19)
vacancy_tract_18_tibble <- stastibble(vacancy_tract_18)
vacancy_tract_17_tibble <- stastibble(vacancy_tract_17)
vacancy_tract_16_tibble <- stastibble(vacancy_tract_16)
vacancy_tract_15_tibble <- stastibble(vacancy_tract_15)
vacancy_tract_14_tibble <- stastibble(vacancy_tract_14)
vacancy_tract_13_tibble <- stastibble(vacancy_tract_13)
vacancy_tract_12_tibble <- stastibble(vacancy_tract_12)
vacancy_tract_11_tibble <- stastibble(vacancy_tract_11)
vacancy_tract_10_tibble <- stastibble(vacancy_tract_10)
vacancy_joined <- left_join(vacancy_tract_21_tibble, vacancy_tract_20_tibble %>% dplyr::select(estimate, GEOID), by = 'GEOID')
vacancy_joined <- left_join(vacancy_joined, vacancy_tract_19_tibble %>% dplyr::select(estimate, GEOID), by = 'GEOID')
vacancy_joined <- left_join(vacancy_joined, vacancy_tract_18_tibble %>% dplyr::select(estimate, GEOID), by = 'GEOID')
vacancy_joined <- left_join(vacancy_joined, vacancy_tract_17_tibble %>% dplyr::select(estimate, GEOID), by = 'GEOID')
vacancy_joined <- left_join(vacancy_joined, vacancy_tract_16_tibble %>% dplyr::select(estimate, GEOID), by = 'GEOID')
vacancy_joined <- left_join(vacancy_joined, vacancy_tract_15_tibble %>% dplyr::select(estimate, GEOID), by = 'GEOID')
vacancy_joined <- left_join(vacancy_joined, vacancy_tract_14_tibble %>% dplyr::select(estimate, GEOID), by = 'GEOID')
vacancy_joined <- left_join(vacancy_joined, vacancy_tract_13_tibble %>% dplyr::select(estimate, GEOID), by = 'GEOID')
vacancy_joined <- left_join(vacancy_joined, vacancy_tract_12_tibble %>% dplyr::select(estimate, GEOID), by = 'GEOID')
vacancy_joined<- left_join(vacancy_joined, vacancy_tract_11_tibble %>% dplyr::select(estimate, GEOID), by = 'GEOID')
vacancy_joined <- left_join(vacancy_joined, vacancy_tract_10_tibble %>% dplyr::select(estimate, GEOID), by = 'GEOID')
colnames(vacancy_joined)[4] = "est2021"
colnames(vacancy_joined)[7] = "est2020"
colnames(vacancy_joined)[8] = "est2019"
colnames(vacancy_joined)[9] = "est2018"
colnames(vacancy_joined)[10] = "est2017"
colnames(vacancy_joined)[11] = "est2016"
colnames(vacancy_joined)[12] = "est2015"
colnames(vacancy_joined)[13] = "est2014"
colnames(vacancy_joined)[14] = "est2013"
colnames(vacancy_joined)[15] = "est2012"
colnames(vacancy_joined)[16] = "est2011"
colnames(vacancy_joined)[17] = "est2010"
vacancy_joined_sf <- st_as_sf(vacancy_joined, sf_column_name = 'geometry', crs = 4326)
Warning: st_crs<- : replacing crs does not reproject data; use st_transform for that
vacancy_joined_sf <- drop_na(vacancy_joined_sf)
vacancy_joined_Sf_long <- pivot_longer(data = vacancy_joined_sf, cols =c(est2021, est2020:est2010))
vacancy_joined_Sf_long$name[vacancy_joined_Sf_long$name == 'est2021'] <- '2021'
vacancy_joined_Sf_long$name[vacancy_joined_Sf_long$name == 'est2020'] <- '2020'
vacancy_joined_Sf_long$name[vacancy_joined_Sf_long$name == 'est2019'] <- '2019'
vacancy_joined_Sf_long$name[vacancy_joined_Sf_long$name == 'est2018'] <- '2018'
vacancy_joined_Sf_long$name[vacancy_joined_Sf_long$name == 'est2017'] <- '2017'
vacancy_joined_Sf_long$name[vacancy_joined_Sf_long$name == 'est2016'] <- '2016'
vacancy_joined_Sf_long$name[vacancy_joined_Sf_long$name == 'est2015'] <- '2015'
vacancy_joined_Sf_long$name[vacancy_joined_Sf_long$name == 'est2014'] <- '2014'
vacancy_joined_Sf_long$name[vacancy_joined_Sf_long$name == 'est2013'] <- '2013'
vacancy_joined_Sf_long$name[vacancy_joined_Sf_long$name == 'est2012'] <- '2012'
vacancy_joined_Sf_long$name[vacancy_joined_Sf_long$name == 'est2011'] <- '2011'
vacancy_joined_Sf_long$name[vacancy_joined_Sf_long$name == 'est2010'] <- '2010'
colnames(vacancy_joined_Sf_long)[6] <- 'year'
vacancy_joined_Sf_long$year <- as.integer(vacancy_joined_Sf_long$year)
detroit_map_vacancy_gif <- ggplot() + geom_sf(data = vacancy_joined_Sf_long, color = "black", aes(fill = value)) + theme_light(base_size = 10) + scale_fill_gradient(low = "lightyellow1", high = "darkorchid4") + transition_time(year) + labs(title = "Vacancy by Census Tract by Year: {frame_time}")
detroit_map_vacancy_gif
Detroit_sidelots <- read_json("Side_Lots_Sold.geojson")
Detroit_propertysales <- read_csv("property_sales.csv")
Rows: 377839 Columns: 16── Column specification ──────────────────────────────────────────────────────────────────────────
Delimiter: ","
chr (10): parcel_number, address, grantor, grantee, liberpage, sale_terms, verified_by, sale_...
dbl (4): object_id, sale_number, sale_price, sale_trans
lgl (1): geom
date (1): sale_date
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
detroit_property_sales_year <- format(as.Date(Detroit_propertysales$sale_date, format="%Y/%m/%d"),"%Y")
data.frame(detroit_property_sales_year)
detroit_propsales_year_1 <- cbind(detroit_property_sales_year, Detroit_propertysales)
detroit_propsales_year_1
Detroit_propertysales_2011 <- detroit_propsales_year_1 %>% filter(detroit_property_sales_year == 2011)
Detroit_propertysales_2012 <- detroit_propsales_year_1 %>% filter(detroit_property_sales_year == 2012)
Detroit_propertysales_2013 <- detroit_propsales_year_1 %>% filter(detroit_property_sales_year == 2013)
Detroit_propertysales_2014 <- detroit_propsales_year_1 %>% filter(detroit_property_sales_year == 2014)
Detroit_propertysales_2015 <- detroit_propsales_year_1 %>% filter(detroit_property_sales_year == 2015)
Detroit_propertysales_2016 <- detroit_propsales_year_1 %>% filter(detroit_property_sales_year == 2016)
Detroit_propertysales_2017 <- detroit_propsales_year_1 %>% filter(detroit_property_sales_year == 2017)
Detroit_propertysales_2018 <- detroit_propsales_year_1 %>% filter(detroit_property_sales_year == 2018)
Detroit_propertysales_2019 <- detroit_propsales_year_1 %>% filter(detroit_property_sales_year == 2019)
Detroit_propertysales_2020 <- detroit_propsales_year_1 %>% filter(detroit_property_sales_year == 2020)
Detroit_propertysales_2021 <- detroit_propsales_year_1 %>% filter(detroit_property_sales_year == 2021)
Detroit_propertysales_2022 <- detroit_propsales_year_1 %>% filter(detroit_property_sales_year == 2022)
sum_detroit_propsales_year_1 <- aggregate(x = detroit_propsales_year_1$sale_price,
by = list(detroit_propsales_year_1$detroit_property_sales_year),
FUN = sum)
colnames(sum_detroit_propsales_year_1)[1] = 'year'
colnames(sum_detroit_propsales_year_1)[2] = 'price'
sum_detroit_propsales_year_1$year <- as.integer(sum_detroit_propsales_year_1$year)
detroit_line_graph_salesprices <- ggplot()+ geom_point(data = sum_detroit_propsales_year_1, aes(x = year, y= price)) + theme_bw() + transition_time(year) + labs(title = "Real Estate Prices in Detroit by Year: {frame_time}")
detroit_line_graph_salesprices
avg_detroit_propsales_year_1 <- aggregate(x = detroit_propsales_year_1$sale_price,
by = list(detroit_propsales_year_1$detroit_property_sales_year),
FUN = mean)
colnames(avg_detroit_propsales_year_1)[1] = 'year'
colnames(avg_detroit_propsales_year_1)[2] = 'price'
avg_detroit_propsales_year_1$year <- as.integer(avg_detroit_propsales_year_1$year)
detroit_line_graph_salesprices_avg <- ggplot()+ geom_point(data = avg_detroit_propsales_year_1, aes(x = year, y= price)) + theme_bw() + transition_time(year) + labs(title = " Average Real Estate Prices in Detroit by Year: {frame_time}")
detroit_line_graph_salesprices_avg
detroitsales_401 <- detroit_propsales_year_1 %>% dplyr::filter(., property_class == 401)
detroitsales_402 <- detroit_propsales_year_1 %>% dplyr::filter(., property_class == 402)
sum_detroit_propsales_year_401 <- aggregate(x = detroitsales_401$sale_price,
by = list(detroitsales_401$detroit_property_sales_year),
FUN = sum)
colnames(sum_detroit_propsales_year_401)[1] = 'year'
colnames(sum_detroit_propsales_year_401)[2] = 'price'
sum_detroit_propsales_year_401$year <- as.integer(sum_detroit_propsales_year_401$year)
detroit_line_graph_salesprices_401 <- ggplot()+ geom_point(data = sum_detroit_propsales_year_401, aes(x = year, y= price)) + theme_bw() + transition_time(year) + labs(title = "Real Estate Prices - Residential in Nature and Improved in Detroit by Year: {frame_time}")
detroit_line_graph_salesprices_401
avg_detroit_propsales_year_401 <- aggregate(x = detroitsales_401$sale_price,
by = list(detroitsales_401$detroit_property_sales_year),
FUN = mean)
colnames(avg_detroit_propsales_year_401)[1] = 'year'
colnames(avg_detroit_propsales_year_401)[2] = 'price'
avg_detroit_propsales_year_401$year <- as.integer(avg_detroit_propsales_year_401$year)
detroit_line_graph_salesprices_401_avg <- ggplot()+ geom_point(data = avg_detroit_propsales_year_401, aes(x = year, y= price)) + theme_bw() + transition_time(year) + labs(title = " Average Real Estate Prices - Residential in Nature and Improved in Detroit by Year: {frame_time}")
detroit_line_graph_salesprices_401_avg
sum_detroit_propsales_year_402 <- aggregate(x = detroitsales_402$sale_price,
by = list(detroitsales_402$detroit_property_sales_year),
FUN = sum)
colnames(sum_detroit_propsales_year_402)[1] = 'year'
colnames(sum_detroit_propsales_year_402)[2] = 'price'
sum_detroit_propsales_year_402$year <- as.integer(sum_detroit_propsales_year_402$year)
detroit_line_graph_salesprices_402 <- ggplot()+ geom_point(data = sum_detroit_propsales_year_402, aes(x = year, y= price), color = "royalblue", size = 4) + theme_bw() + transition_time(year) + labs(title = "Real Estate Prices - Residential and Vacant in Detroit by Year: {frame_time}")
detroit_line_graph_salesprices_402
avg_detroit_propsales_year_402 <- aggregate(x = detroitsales_402$sale_price,
by = list(detroitsales_402$detroit_property_sales_year),
FUN = mean)
colnames(avg_detroit_propsales_year_402)[1] = 'year'
colnames(avg_detroit_propsales_year_402)[2] = 'price'
avg_detroit_propsales_year_402$year <- as.integer(avg_detroit_propsales_year_402$year)
detroit_line_graph_salesprices_402_avg <- ggplot()+ geom_point(data = avg_detroit_propsales_year_402, aes(x = year, y= price)) + theme_bw() + transition_time(year) + labs(title = " Average Real Estate Prices - Residential and Vacant in Detroit by Year: {frame_time}")
detroit_line_graph_salesprices_402_avg
residential_demolitions <- read_csv("Completed_Residential_Demolitions.csv")
Rows: 25604 Columns: 21── Column specification ──────────────────────────────────────────────────────────────────────────
Delimiter: ","
chr (13): address, parcel_id, contractor_name, funding_source, demolition_date, demo_rfp_group...
dbl (8): X, Y, price, council_district, street_number, property_longitude, property_latitude,...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
year_demo<- format(as.Date(residential_demolitions$demolition_date, format="%Y/%m/%d"),"%Y")
data.frame(residential_demolitions)
residential_demo_year <- cbind(year_demo, residential_demolitions)
residential_demo_year
residential_demo_year <- st_as_sf(residential_demo_year, coords = c("X", "Y"), crs = 4326)
residential_demo_year$year_demo <- as.integer(residential_demo_year$year_demo)
detroit_map_demo_gif <- ggplot() + geom_sf(data = residential_demo_year, color = "darkgreen", aes(fill = year_demo), size = .05, alpha = .5) + theme_light(base_size = 10) + scale_fill_gradient(low = "lightyellow1", high = "darkorchid4")
detroit_map_demo_gif
residential_demo_year$year_demo <- as.integer(residential_demo_year$year_demo)
detroit_map_demo_gif <- ggplot() + geom_sf(data = residential_demo_year, color = "darkgreen", aes(fill = year_demo), size = .05, alpha = .5) + theme_light(base_size = 10) + scale_fill_gradient(low = "lightyellow1", high = "darkorchid4") + transition_time(year_demo) + labs(title = "Demolitions by Year: {frame_time}")
detroit_map_demo_gif
anim_save("detroit_map_demo_gif.gif", detroit_map_demo_gif)
anim_save("detroit_map_pop_gif.gif", detroit_map_pop_gif)
anim_save("detroit_line_graph_population.gif", detroit_line_graph_population)
anim_save("detroit_line_graph_vacancies_1.gif", detroit_line_graph_vacancies_1)
anim_save("detroit_line_graph_vacancies_2.gif", detroit_line_graph_vacancies_2)
anim_save("detroit_map_vacancy_gif.gif", detroit_map_vacancy_gif)
anim_save("detroit_line_graph_salesprices.gif", detroit_line_graph_salesprices)
anim_save("detroit_line_graph_salesprices_401.gif", detroit_line_graph_salesprices_401)
anim_save("detroit_line_graph_salesprices_402.gif", detroit_line_graph_salesprices_402)
anim_save("detroit_line_graph_salesprices_401_avg.gif", detroit_line_graph_salesprices_401_avg)
anim_save("detroit_line_graph_salesprices_402_avg.gif", detroit_line_graph_salesprices_402_avg)
anim_save("detroit_line_graph_salesprices_avg.gif", detroit_line_graph_salesprices_avg)
install.packages("gifski")
Error in install.packages : Updating loaded packages
library(gifski)
library(rsconnect)
library(shiny)
Attaching package: ‘shiny’
The following object is masked from ‘package:rsconnect’:
serverInfo