# 1. Redo the analysis for mapping Hispanic population and add histogram in the map (2').
library(tidycensus)
census_api_key("bd2af251ff3d1ee389e731f6d917f605cb300fdb", overwrite = "TRUE")
## To install your API key for use in future sessions, run this function with `install = TRUE`.
var=c('B03002_012E','B03002_004E','B05003_002E', 'B05003_013E','B01001_001E', 'B01002I_001E', 'B19013I_001E')
Miami_segregation <- get_acs(geography = "tract", variables = var, county = "Miami-Dade",
state = "FL",output="wide", geometry = TRUE)
## Getting data from the 2017-2021 5-year ACS
## Downloading feature geometry from the Census website. To cache shapefiles for use in future sessions, set `options(tigris_use_cache = TRUE)`.
##
|
| | 0%
|
|= | 1%
|
|= | 2%
|
|== | 2%
|
|== | 3%
|
|=== | 4%
|
|=== | 5%
|
|==== | 5%
|
|==== | 6%
|
|===== | 7%
|
|===== | 8%
|
|====== | 8%
|
|====== | 9%
|
|======= | 10%
|
|======= | 11%
|
|======== | 11%
|
|======== | 12%
|
|========= | 13%
|
|========= | 14%
|
|========== | 14%
|
|========== | 15%
|
|=========== | 16%
|
|============ | 16%
|
|============ | 17%
|
|============= | 18%
|
|============= | 19%
|
|============== | 19%
|
|============== | 20%
|
|=============== | 21%
|
|=============== | 22%
|
|================ | 22%
|
|================ | 23%
|
|================= | 24%
|
|================== | 25%
|
|================== | 26%
|
|=================== | 27%
|
|==================== | 28%
|
|==================== | 29%
|
|===================== | 30%
|
|====================== | 31%
|
|====================== | 32%
|
|======================= | 33%
|
|========================= | 36%
|
|========================== | 37%
|
|========================== | 38%
|
|=========================== | 39%
|
|============================ | 40%
|
|============================= | 41%
|
|============================= | 42%
|
|============================== | 42%
|
|============================== | 43%
|
|=============================== | 44%
|
|================================ | 45%
|
|================================ | 46%
|
|================================= | 47%
|
|================================== | 48%
|
|================================== | 49%
|
|=================================== | 50%
|
|==================================== | 51%
|
|===================================== | 53%
|
|====================================== | 54%
|
|====================================== | 55%
|
|======================================= | 56%
|
|======================================== | 57%
|
|========================================= | 58%
|
|========================================= | 59%
|
|========================================== | 60%
|
|=========================================== | 61%
|
|=========================================== | 62%
|
|============================================ | 62%
|
|============================================ | 63%
|
|============================================= | 64%
|
|============================================= | 65%
|
|============================================== | 65%
|
|============================================== | 66%
|
|=============================================== | 67%
|
|================================================ | 68%
|
|================================================ | 69%
|
|================================================= | 70%
|
|================================================== | 71%
|
|================================================== | 72%
|
|=================================================== | 73%
|
|==================================================== | 74%
|
|==================================================== | 75%
|
|===================================================== | 76%
|
|====================================================== | 77%
|
|======================================================= | 78%
|
|======================================================= | 79%
|
|======================================================== | 79%
|
|======================================================== | 80%
|
|========================================================= | 81%
|
|========================================================= | 82%
|
|========================================================== | 82%
|
|========================================================== | 83%
|
|=========================================================== | 84%
|
|=========================================================== | 85%
|
|============================================================ | 85%
|
|============================================================ | 86%
|
|============================================================= | 87%
|
|============================================================= | 88%
|
|============================================================== | 88%
|
|============================================================== | 89%
|
|=============================================================== | 90%
|
|================================================================ | 91%
|
|================================================================ | 92%
|
|================================================================= | 93%
|
|================================================================== | 94%
|
|================================================================== | 95%
|
|=================================================================== | 96%
|
|==================================================================== | 97%
|
|===================================================================== | 98%
|
|===================================================================== | 99%
|
|======================================================================| 99%
|
|======================================================================| 100%
names(Miami_segregation)[3] <- 'Hispanic'
names(Miami_segregation)[5] <- 'Black or African American'
names(Miami_segregation)[7] <- 'Male'
names(Miami_segregation)[9] <- 'Female'
names(Miami_segregation)[11] <- 'TotalPop'
names(Miami_segregation)[13] <- 'MedianAge'
names(Miami_segregation)[15] <- 'MedianHouseholdIncome'
Miami_segregation$B03002_012M <- NULL
Miami_segregation$B03002_004M <- NULL
Miami_segregation$B05003_002M <- NULL
Miami_segregation$B05003_013M <- NULL
Miami_segregation$B01001_001M <- NULL
Miami_segregation$B01002I_001M <- NULL
Miami_segregation$B19013I_001M <- NULL
library(tmap)
## The legacy packages maptools, rgdal, and rgeos, underpinning the sp package,
## which was just loaded, will retire in October 2023.
## Please refer to R-spatial evolution reports for details, especially
## https://r-spatial.org/r/2023/05/15/evolution4.html.
## It may be desirable to make the sf package available;
## package maintainers should consider adding sf to Suggests:.
## The sp package is now running under evolution status 2
## (status 2 uses the sf package in place of rgdal)
## Breaking News: tmap 3.x is retiring. Please test v4, e.g. with
## remotes::install_github('r-tmap/tmap')
library(sf)
## Linking to GEOS 3.11.0, GDAL 3.5.3, PROJ 9.1.0; sf_use_s2() is TRUE
Miami_segregation$pct_Hisp <- 100*Miami_segregation$Hispanic/Miami_segregation$TotalPop
Miami_segregation <- Miami_segregation[-707,]
tm_shape(Miami_segregation) +tm_fill(col = "pct_Hisp")+ tm_layout(title = "Hispanic Percent")
tm_shape(Miami_segregation) +
tm_fill(col = "Hispanic",legend.hist = TRUE)+
tm_layout(title = "Hispanic Pop")+
tm_layout(legend.outside = TRUE,frame = FALSE)
# 2. Following Q1, add border for census tracts (1').
tm_shape(Miami_segregation) +
tm_fill(col = "Hispanic",legend.hist = TRUE)+
tm_layout(title = "Hispanic Pop")+
tm_borders(alpha=.4) +
tm_layout(legend.outside = TRUE,frame = FALSE)
# 3. Following Q2, add compass and scale bar for the map (1').
tmap_mode("plot")
## tmap mode set to plotting
tm_shape(Miami_segregation) +
tm_fill(col = "Hispanic", legend.hist = TRUE)+
tm_layout(title = "Hispanic Pop")+
tm_borders(alpha=.4) +
tm_compass(type = "8star",
position = c("RIGHT", "BOTTOM"),
show.labels = 2,
text.size = 0.6) +
tm_layout(legend.outside = TRUE,frame = TRUE)+
tm_scale_bar(position = c("RIGHT", "BOTTOM"))
# 4. Following Q3, set color intervals as "red" for the map (1').
tm_shape(Miami_segregation) +
tm_fill(col = "Hispanic", palette = "Reds", legend.hist = TRUE)+
tm_layout(title = "Hispanic Pop")+
tm_borders(alpha=.4) +
tm_compass(type = "8star",
position = c("RIGHT", "BOTTOM"),
show.labels = 2,
text.size = 0.6) +
tm_layout(legend.outside = TRUE,frame = TRUE)+
tm_scale_bar(position = c("RIGHT", "BOTTOM"))
# 5. Make an interactive map to show the spatial distribution of percentage of Hispanic population (2').
tmap_mode("view")
## tmap mode set to interactive viewing
tm_shape(Miami_segregation) +
tm_fill(col = "Hispanic", palette = "Reds", legend.hist = TRUE)+
tm_layout(title = "Hispanic Pop")+
tm_borders(alpha=.4) +
tm_layout(legend.outside = TRUE,frame = TRUE)+
tm_scale_bar(position = c("RIGHT", "BOTTOM"))
# 6. Retrieve the census tract shapefile data of the county (1').
census_tract <-st_read(dsn = "/Users/gabbyrodriguez/Documents/UTSA MSURP/Urban Planning Methods/Project 2/Census Tract Data/Tract.shp")
## Reading layer `Tract' from data source
## `/Users/gabbyrodriguez/Documents/UTSA MSURP/Urban Planning Methods/Project 2/Census Tract Data/Tract.shp'
## using driver `ESRI Shapefile'
## Simple feature collection with 707 features and 74 fields
## Geometry type: MULTIPOLYGON
## Dimension: XY
## Bounding box: xmin: -80.8736 ymin: 25.13742 xmax: -80.06279 ymax: 25.97944
## Geodetic CRS: WGS 84
# 7. Find any point shapefile data within the county and make a map with census tract as the background (2').
library(tigris)
## To enable caching of data, set `options(tigris_use_cache = TRUE)`
## in your R script or .Rprofile.
MIA_Library <-st_read(dsn = "/Users/gabbyrodriguez/Documents/UTSA MSURP/Urban Planning Methods/Project 2/County_Library/Library.shp")
## Reading layer `Library' from data source
## `/Users/gabbyrodriguez/Documents/UTSA MSURP/Urban Planning Methods/Project 2/County_Library/Library.shp'
## using driver `ESRI Shapefile'
## Simple feature collection with 50 features and 25 fields
## Geometry type: POINT
## Dimension: XY
## Bounding box: xmin: -80.44164 ymin: 25.50632 xmax: -80.12072 ymax: 25.9604
## Geodetic CRS: WGS 84
MIA_Library <- st_transform(MIA_Library, crs=4326)
Miami_tracts<- tracts(state = "FL", county = "Miami-Dade",cb=T)
## Retrieving data for the year 2021
tmap_mode("view")
## tmap mode set to interactive viewing
tm_shape(Miami_tracts) +
tm_borders() + # Add borders for polygons (customize as needed)
tm_shape(MIA_Library) +
tm_dots(size = 0.02, col = "red", alpha = 0.7) + # Customize point appearance
tm_layout(title = "Miami-Dade Libraries", frame = FALSE)
# 8. Find any line shapefile data within the county and make a map with census tract as the background (2').
bike_lanes <-st_read(dsn = "/Users/gabbyrodriguez/Documents/UTSA MSURP/Urban Planning Methods/Project 2/Bike_lane/BikeLane.shp")
## Reading layer `BikeLane' from data source
## `/Users/gabbyrodriguez/Documents/UTSA MSURP/Urban Planning Methods/Project 2/Bike_Lane/BikeLane.shp'
## using driver `ESRI Shapefile'
## Simple feature collection with 178 features and 5 fields
## Geometry type: LINESTRING
## Dimension: XY
## Bounding box: xmin: -80.48534 ymin: 25.43657 xmax: -80.12091 ymax: 25.97454
## Geodetic CRS: WGS 84
bike_lanes <- st_transform(bike_lanes, crs=4326)
Miami_tracts<- tracts(state = "FL", county = "Miami-Dade",cb=T)
## Retrieving data for the year 2021
buffer_distance <- 0.5 # adjust as needed
lines_polygon <- st_buffer(bike_lanes, dist = buffer_distance)
tm_shape(Miami_tracts) +
tm_borders() +
tm_shape(lines_polygon) +
tm_borders(lwd = 2, col = "green") + # Customize line appearance
tm_layout(frame = FALSE)