Package
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ ggplot2 4.0.0 ✔ tibble 3.3.0
## ✔ lubridate 1.9.4 ✔ tidyr 1.3.1
## ✔ purrr 1.1.0
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(lubridate)
library(sf)
## Linking to GEOS 3.13.1, GDAL 3.11.0, PROJ 9.6.0; sf_use_s2() is TRUE
library(tmap)
library(lubridate)
library(pdftools)
## Warning: package 'pdftools' was built under R version 4.5.2
## Using poppler version 25.10.0
vehicle.data <- read_csv("D:/Kuliah/IPB 2025 Semester 3/Analisis Spasial/Praktikum/Bedah Buku Spasial/suj7-cg3j.csv")
## Rows: 1000 Columns: 26
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (10): status, service_request_number, type_of_service_request, license_...
## dbl (10): how_many_days_has_the_vehicle_been_reported_as_parked_, zip_code,...
## lgl (4): location_address, location_city, location_state, location_zip
## dttm (2): creation_date, completion_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.
# --- 2. Cek variabel ---
head(vehicle.data)
## # A tibble: 6 × 26
## creation_date status completion_date service_request_number
## <dttm> <chr> <dttm> <chr>
## 1 2011-11-22 00:00:00 Completed 2011-12-16 00:00:00 11-04160439
## 2 2015-08-06 00:00:00 Completed 2015-08-27 00:00:00 15-03899542
## 3 2018-08-01 00:00:00 Completed - Dup 2018-08-02 00:00:00 18-02273196
## 4 2015-10-31 00:00:00 Completed 2015-11-17 00:00:00 15-05859893
## 5 2018-08-17 00:00:00 Completed 2018-09-27 00:00:00 18-02415501
## 6 2015-09-03 00:00:00 Completed 2015-09-09 00:00:00 15-04542748
## # ℹ 22 more variables: type_of_service_request <chr>, license_plate <chr>,
## # vehicle_make_model <chr>, vehicle_color <chr>, current_activity <chr>,
## # most_recent_action <chr>,
## # how_many_days_has_the_vehicle_been_reported_as_parked_ <dbl>,
## # street_address <chr>, zip_code <dbl>, x_coordinate <dbl>,
## # y_coordinate <dbl>, ward <dbl>, police_district <dbl>,
## # community_area <dbl>, ssa <dbl>, latitude <dbl>, longitude <dbl>, …
names(vehicle.data)
## [1] "creation_date"
## [2] "status"
## [3] "completion_date"
## [4] "service_request_number"
## [5] "type_of_service_request"
## [6] "license_plate"
## [7] "vehicle_make_model"
## [8] "vehicle_color"
## [9] "current_activity"
## [10] "most_recent_action"
## [11] "how_many_days_has_the_vehicle_been_reported_as_parked_"
## [12] "street_address"
## [13] "zip_code"
## [14] "x_coordinate"
## [15] "y_coordinate"
## [16] "ward"
## [17] "police_district"
## [18] "community_area"
## [19] "ssa"
## [20] "latitude"
## [21] "longitude"
## [22] "location"
## [23] "location_address"
## [24] "location_city"
## [25] "location_state"
## [26] "location_zip"
dim(vehicle.data)
## [1] 1000 26
Mengekstraksi observasi untuk periode waktu yang diinginkan (Optional)
## # A tibble: 6 × 26
## creation_date status completion_date service_request_number
## <dttm> <chr> <dttm> <chr>
## 1 2016-09-19 00:00:00 Completed - Dup 2016-09-20 00:00:00 16-06626081
## 2 2016-09-18 00:00:00 Completed 2016-09-26 00:00:00 16-06609139
## 3 2016-09-05 00:00:00 Completed 2016-09-16 00:00:00 16-06288316
## 4 2016-09-19 00:00:00 Completed 2016-09-26 00:00:00 16-06630847
## 5 2016-09-15 00:00:00 Completed 2016-11-07 00:00:00 16-06551384
## 6 2016-09-07 00:00:00 Completed 2016-10-21 00:00:00 16-06346749
## # ℹ 22 more variables: type_of_service_request <chr>, license_plate <chr>,
## # vehicle_make_model <chr>, vehicle_color <chr>, current_activity <chr>,
## # most_recent_action <chr>,
## # how_many_days_has_the_vehicle_been_reported_as_parked_ <dbl>,
## # street_address <chr>, zip_code <dbl>, x_coordinate <dbl>,
## # y_coordinate <dbl>, ward <dbl>, police_district <dbl>,
## # community_area <dbl>, ssa <dbl>, latitude <dbl>, longitude <dbl>, …
## [1] 9 26
vehicles.final <- vehicle.data %>%
select(comm = community_area,
lat = latitude,
lon = longitude)
head(vehicles.final)
## # A tibble: 6 × 3
## comm lat lon
## <dbl> <dbl> <dbl>
## 1 6 41.9 -87.6
## 2 6 41.9 -87.6
## 3 6 41.9 -87.6
## 4 6 41.9 -87.6
## 5 6 41.9 -87.6
## 6 6 41.9 -87.6
dim(vehicles.final)
## [1] 1000 3
names(vehicle.sept16)
## [1] "creation_date"
## [2] "status"
## [3] "completion_date"
## [4] "service_request_number"
## [5] "type_of_service_request"
## [6] "license_plate"
## [7] "vehicle_make_model"
## [8] "vehicle_color"
## [9] "current_activity"
## [10] "most_recent_action"
## [11] "how_many_days_has_the_vehicle_been_reported_as_parked_"
## [12] "street_address"
## [13] "zip_code"
## [14] "x_coordinate"
## [15] "y_coordinate"
## [16] "ward"
## [17] "police_district"
## [18] "community_area"
## [19] "ssa"
## [20] "latitude"
## [21] "longitude"
## [22] "location"
## [23] "location_address"
## [24] "location_city"
## [25] "location_state"
## [26] "location_zip"
vehicle.coord <- vehicles.final %>%
filter(!is.na(lat))
dim(vehicle.coord)
## [1] 1000 3
vehicle.points <- st_as_sf(
vehicle.coord,
coords = c("lon", "lat"),
crs = 4326,
agr = "constant"
)
st_crs(vehicle.points)
## Coordinate Reference System:
## User input: EPSG:4326
## wkt:
## GEOGCRS["WGS 84",
## ENSEMBLE["World Geodetic System 1984 ensemble",
## MEMBER["World Geodetic System 1984 (Transit)"],
## MEMBER["World Geodetic System 1984 (G730)"],
## MEMBER["World Geodetic System 1984 (G873)"],
## MEMBER["World Geodetic System 1984 (G1150)"],
## MEMBER["World Geodetic System 1984 (G1674)"],
## MEMBER["World Geodetic System 1984 (G1762)"],
## MEMBER["World Geodetic System 1984 (G2139)"],
## MEMBER["World Geodetic System 1984 (G2296)"],
## ELLIPSOID["WGS 84",6378137,298.257223563,
## LENGTHUNIT["metre",1]],
## ENSEMBLEACCURACY[2.0]],
## PRIMEM["Greenwich",0,
## ANGLEUNIT["degree",0.0174532925199433]],
## CS[ellipsoidal,2],
## AXIS["geodetic latitude (Lat)",north,
## ORDER[1],
## ANGLEUNIT["degree",0.0174532925199433]],
## AXIS["geodetic longitude (Lon)",east,
## ORDER[2],
## ANGLEUNIT["degree",0.0174532925199433]],
## USAGE[
## SCOPE["Horizontal component of 3D system."],
## AREA["World."],
## BBOX[-90,-180,90,180]],
## ID["EPSG",4326]]
plot(vehicle.points)
#ambil data border
comm.file <- "https://data.cityofchicago.org/resource/igwz-8jzy.geojson"
chicago.comm <- read_sf(comm.file)
class(chicago.comm)
## [1] "sf" "tbl_df" "tbl" "data.frame"
st_crs(chicago.comm)
## Coordinate Reference System:
## User input: WGS 84
## wkt:
## GEOGCRS["WGS 84",
## DATUM["World Geodetic System 1984",
## ELLIPSOID["WGS 84",6378137,298.257223563,
## LENGTHUNIT["metre",1]]],
## PRIMEM["Greenwich",0,
## ANGLEUNIT["degree",0.0174532925199433]],
## CS[ellipsoidal,2],
## AXIS["geodetic latitude (Lat)",north,
## ORDER[1],
## ANGLEUNIT["degree",0.0174532925199433]],
## AXIS["geodetic longitude (Lon)",east,
## ORDER[2],
## ANGLEUNIT["degree",0.0174532925199433]],
## ID["EPSG",4326]]
plot(chicago.comm)
# Proyeksi ke UTM Zona 16 Utara
chicago.comm <- st_transform(chicago.comm, 32616)
vehicle.points <- st_transform(vehicle.points, 32616)
st_crs(chicago.comm)
## Coordinate Reference System:
## User input: EPSG:32616
## wkt:
## PROJCRS["WGS 84 / UTM zone 16N",
## BASEGEOGCRS["WGS 84",
## ENSEMBLE["World Geodetic System 1984 ensemble",
## MEMBER["World Geodetic System 1984 (Transit)"],
## MEMBER["World Geodetic System 1984 (G730)"],
## MEMBER["World Geodetic System 1984 (G873)"],
## MEMBER["World Geodetic System 1984 (G1150)"],
## MEMBER["World Geodetic System 1984 (G1674)"],
## MEMBER["World Geodetic System 1984 (G1762)"],
## MEMBER["World Geodetic System 1984 (G2139)"],
## MEMBER["World Geodetic System 1984 (G2296)"],
## ELLIPSOID["WGS 84",6378137,298.257223563,
## LENGTHUNIT["metre",1]],
## ENSEMBLEACCURACY[2.0]],
## PRIMEM["Greenwich",0,
## ANGLEUNIT["degree",0.0174532925199433]],
## ID["EPSG",4326]],
## CONVERSION["UTM zone 16N",
## METHOD["Transverse Mercator",
## ID["EPSG",9807]],
## PARAMETER["Latitude of natural origin",0,
## ANGLEUNIT["degree",0.0174532925199433],
## ID["EPSG",8801]],
## PARAMETER["Longitude of natural origin",-87,
## ANGLEUNIT["degree",0.0174532925199433],
## ID["EPSG",8802]],
## PARAMETER["Scale factor at natural origin",0.9996,
## SCALEUNIT["unity",1],
## ID["EPSG",8805]],
## PARAMETER["False easting",500000,
## LENGTHUNIT["metre",1],
## ID["EPSG",8806]],
## PARAMETER["False northing",0,
## LENGTHUNIT["metre",1],
## ID["EPSG",8807]]],
## CS[Cartesian,2],
## AXIS["(E)",east,
## ORDER[1],
## LENGTHUNIT["metre",1]],
## AXIS["(N)",north,
## ORDER[2],
## LENGTHUNIT["metre",1]],
## USAGE[
## SCOPE["Navigation and medium accuracy spatial referencing."],
## AREA["Between 90°W and 84°W, northern hemisphere between equator and 84°N, onshore and offshore. Belize. Canada - Manitoba; Nunavut; Ontario. Costa Rica. Cuba. Ecuador - Galapagos. El Salvador. Guatemala. Honduras. Mexico. Nicaragua. United States (USA)."],
## BBOX[0,-90,84,-84]],
## ID["EPSG",32616]]
st_crs(vehicle.points)
## Coordinate Reference System:
## User input: EPSG:32616
## wkt:
## PROJCRS["WGS 84 / UTM zone 16N",
## BASEGEOGCRS["WGS 84",
## ENSEMBLE["World Geodetic System 1984 ensemble",
## MEMBER["World Geodetic System 1984 (Transit)"],
## MEMBER["World Geodetic System 1984 (G730)"],
## MEMBER["World Geodetic System 1984 (G873)"],
## MEMBER["World Geodetic System 1984 (G1150)"],
## MEMBER["World Geodetic System 1984 (G1674)"],
## MEMBER["World Geodetic System 1984 (G1762)"],
## MEMBER["World Geodetic System 1984 (G2139)"],
## MEMBER["World Geodetic System 1984 (G2296)"],
## ELLIPSOID["WGS 84",6378137,298.257223563,
## LENGTHUNIT["metre",1]],
## ENSEMBLEACCURACY[2.0]],
## PRIMEM["Greenwich",0,
## ANGLEUNIT["degree",0.0174532925199433]],
## ID["EPSG",4326]],
## CONVERSION["UTM zone 16N",
## METHOD["Transverse Mercator",
## ID["EPSG",9807]],
## PARAMETER["Latitude of natural origin",0,
## ANGLEUNIT["degree",0.0174532925199433],
## ID["EPSG",8801]],
## PARAMETER["Longitude of natural origin",-87,
## ANGLEUNIT["degree",0.0174532925199433],
## ID["EPSG",8802]],
## PARAMETER["Scale factor at natural origin",0.9996,
## SCALEUNIT["unity",1],
## ID["EPSG",8805]],
## PARAMETER["False easting",500000,
## LENGTHUNIT["metre",1],
## ID["EPSG",8806]],
## PARAMETER["False northing",0,
## LENGTHUNIT["metre",1],
## ID["EPSG",8807]]],
## CS[Cartesian,2],
## AXIS["(E)",east,
## ORDER[1],
## LENGTHUNIT["metre",1]],
## AXIS["(N)",north,
## ORDER[2],
## LENGTHUNIT["metre",1]],
## USAGE[
## SCOPE["Navigation and medium accuracy spatial referencing."],
## AREA["Between 90°W and 84°W, northern hemisphere between equator and 84°N, onshore and offshore. Belize. Canada - Manitoba; Nunavut; Ontario. Costa Rica. Cuba. Ecuador - Galapagos. El Salvador. Guatemala. Honduras. Mexico. Nicaragua. United States (USA)."],
## BBOX[0,-90,84,-84]],
## ID["EPSG",32616]]
comm.pts <- st_join(vehicle.points, chicago.comm["area_num_1"])
# Cek hasil join
head(comm.pts)
## Simple feature collection with 6 features and 2 fields
## Geometry type: POINT
## Dimension: XY
## Bounding box: xmin: 446304.2 ymin: 4642671 xmax: 446921.9 ymax: 4644014
## Projected CRS: WGS 84 / UTM zone 16N
## # A tibble: 6 × 3
## comm geometry area_num_1
## <dbl> <POINT [m]> <chr>
## 1 6 (446309.9 4644014) 6
## 2 6 (446304.2 4642841) 6
## 3 6 (446921.9 4642671) 6
## 4 6 (446673.8 4643159) 6
## 5 6 (446369.6 4643237) 6
## 6 6 (446574.2 4643233) 6
comm.pts$area_num_1 <- as.integer(comm.pts$area_num_1)
chicago.comm$area_num_1 <- as.integer(chicago.comm$area_num_1)
# Hilangkan geometry agar bisa hitung count
st_geometry(comm.pts) <- NULL
veh.cnts <- comm.pts %>%
count(area_num_1) %>%
rename(comm = area_num_1, AGG.COUNT = n)
head(veh.cnts)
## # A tibble: 4 × 2
## comm AGG.COUNT
## <int> <int>
## 1 6 794
## 2 58 21
## 3 71 118
## 4 73 67
# Samakan tipe
veh.cnts$comm <- as.integer(veh.cnts$comm)
# Left join
chicago.comm <- chicago.comm %>%
left_join(veh.cnts, by = c("area_num_1" = "comm"))
head(chicago.comm)
## Simple feature collection with 6 features and 6 fields
## Geometry type: MULTIPOLYGON
## Dimension: XY
## Bounding box: xmin: 441141.3 ymin: 4642477 xmax: 447735.4 ymax: 4652556
## Projected CRS: WGS 84 / UTM zone 16N
## # A tibble: 6 × 7
## community shape_area area_num_1 area_numbe shape_len geometry
## <chr> <chr> <int> <chr> <chr> <MULTIPOLYGON [m]>
## 1 ROGERS P… 51259902.… 1 1 34052.39… (((445789.6 4649780, 445…
## 2 WEST RID… 98429094.… 2 2 43020.68… (((443315.8 4652166, 443…
## 3 UPTOWN 65095642.… 3 3 46972.79… (((446874.2 4644957, 446…
## 4 LINCOLN … 71352328.… 4 4 36624.60… (((444126.1 4647343, 444…
## 5 NORTH CE… 57054167.… 5 5 31391.66… (((444174.4 4642484, 444…
## 6 LAKE VIEW 87214799.… 6 6 51973.09… (((446874.2 4644957, 446…
## # ℹ 1 more variable: AGG.COUNT <int>
tmap_mode("plot")
## ℹ tmap modes "plot" - "view"
## ℹ toggle with `tmap::ttm()`
tm_shape(chicago.comm) +
tm_polygons(
col = "AGG.COUNT",
palette = "Blues",
title = "Jumlah Kendaraan"
) +
tm_layout(frame = FALSE)
##
## ── tmap v3 code detected ───────────────────────────────────────────────────────
## [v3->v4] `tm_tm_polygons()`: migrate the argument(s) related to the scale of
## the visual variable `fill` namely 'palette' (rename to 'values') to fill.scale
## = tm_scale(<HERE>).[v3->v4] `tm_polygons()`: use 'fill' for the fill color of polygons/symbols
## (instead of 'col'), and 'col' for the outlines (instead of 'border.col').[v3->v4] `tm_polygons()`: migrate the argument(s) related to the legend of the
## visual variable `fill` namely 'title' to 'fill.legend = tm_legend(<HERE>)'[cols4all] color palettes: use palettes from the R package cols4all. Run
## `cols4all::c4a_gui()` to explore them. The old palette name "Blues" is named
## "brewer.blues"Multiple palettes called "blues" found: "brewer.blues", "matplotlib.blues". The first one, "brewer.blues", is returned.
table(veh.cnts$comm)
##
## 6 58 71 73
## 1 1 1 1
length(unique(veh.cnts$comm))
## [1] 4
nrow(chicago.comm)
## [1] 77
nrow(vehicle.sept16)
## [1] 9
pdf.file <- "D:/Kuliah/IPB 2025 Semester 3/Analisis Spasial/Praktikum/Bedah Buku Spasial/Census_2010_and_2000_CA_Populations.pdf"
pop.dat <- pdftools::pdf_text(pdf.file)
class(pop.dat)
## [1] "character"
length(pop.dat)
## [1] 2
length(pop.dat[[1]])
## [1] 1
nnlist <- ""
nnlist
## [1] ""
ppage <- strsplit(pop.dat[[1]],split="\n")
ppage[[1]]
## [1] " CITY OF CHICAGO"
## [2] " CENSUS 2010 AND 2000"
## [3] ""
## [4] " Population"
## [5] "Num Community Area 2010 2,000 Difference Percentage"
## [6] " 1 Rogers Park 54,991 63,484 -8,493 -13.4%"
## [7] " 2 West Ridge 71,942 73,199 -1,257 -1.7%"
## [8] " 3 Uptown 56,362 63,551 -7,189 -11.3%"
## [9] " 4 Lincoln Square 39,493 44,574 -5,081 -11.4%"
## [10] " 5 North Center 31,867 31,895 -28 -0.1%"
## [11] " 6 Lake View 94,368 94,817 -449 -0.5%"
## [12] " 7 Lincoln Park 64,116 64,320 -204 -0.3%"
## [13] " 8 Near North Side 80,484 72,811 7,673 10.5%"
## [14] " 9 Edison Park 11,187 11,259 -72 -0.6%"
## [15] " 10 Norwood Park 37,023 37,669 -646 -1.7%"
## [16] " 11 Jefferson Park 25,448 25,859 -411 -1.6%"
## [17] " 12 Forest Glen 18,508 18,165 343 1.9%"
## [18] " 13 North Park 17,931 18,514 -583 -3.1%"
## [19] " 14 Albany Park 51,542 57,655 -6,113 -10.6%"
## [20] " 15 Portage Park 64,124 65,340 -1,216 -1.9%"
## [21] " 16 Irving Park 53,359 58,643 -5,284 -9.0%"
## [22] " 17 Dunning 41,932 42,164 -232 -0.6%"
## [23] " 18 Montclare 13,426 12,646 780 6.2%"
## [24] " 19 Belmont Cragin 78,743 78,144 599 0.8%"
## [25] " 20 Hermosa 25,010 26,908 -1,898 -7.1%"
## [26] " 21 Avondale 39,262 43,083 -3,821 -8.9%"
## [27] " 22 Logan Square 73,595 82,715 -9,120 -11.0%"
## [28] " 23 Humboldt Park 56,323 65,836 -9,513 -14.4%"
## [29] " 24 West Town 81,432 87,435 -6,003 -6.9%"
## [30] " 25 Austin 98,514 117,527 -19,013 -16.2%"
## [31] " 26 West Garfield Park 18,001 23,019 -5,018 -21.8%"
## [32] " 27 East Garfield Park 20,567 20,881 -314 -1.5%"
## [33] " 28 Near West Side 54,881 46,419 8,462 18.2%"
## [34] " 29 North Lawndale 35,912 41,768 -5,856 -14.0%"
## [35] " 30 South Lawndale 79,288 91,071 -11,783 -12.9%"
## [36] " 31 Lower West Side 35,769 44,031 -8,262 -18.8%"
## [37] " 32 Loop 29,283 16,388 12,895 78.7%"
## [38] " 33 Near South Side 21,390 9,509 11,881 124.9%"
## [39] " 34 Armour Square 13,391 12,032 1,359 11.3%"
## [40] " 35 Douglas 18,238 26,470 -8,232 -31.1%"
## [41] " 36 Oakland 5,918 6,110 -192 -3.1%"
## [42] " 37 Fuller Park 2,876 3,420 -544 -15.9%"
## [43] " 38 Grand Boulevard 21,929 28,006 -6,077 -21.7%"
## [44] " 39 Kenwood 17,841 18,363 -522 -2.8%"
## [45] " 40 Washington Park 11,717 14,146 -2,429 -17.2%"
nni <- ppage[[1]]
nni <- nni[-(1:4)]
nni
## [1] "Num Community Area 2010 2,000 Difference Percentage"
## [2] " 1 Rogers Park 54,991 63,484 -8,493 -13.4%"
## [3] " 2 West Ridge 71,942 73,199 -1,257 -1.7%"
## [4] " 3 Uptown 56,362 63,551 -7,189 -11.3%"
## [5] " 4 Lincoln Square 39,493 44,574 -5,081 -11.4%"
## [6] " 5 North Center 31,867 31,895 -28 -0.1%"
## [7] " 6 Lake View 94,368 94,817 -449 -0.5%"
## [8] " 7 Lincoln Park 64,116 64,320 -204 -0.3%"
## [9] " 8 Near North Side 80,484 72,811 7,673 10.5%"
## [10] " 9 Edison Park 11,187 11,259 -72 -0.6%"
## [11] " 10 Norwood Park 37,023 37,669 -646 -1.7%"
## [12] " 11 Jefferson Park 25,448 25,859 -411 -1.6%"
## [13] " 12 Forest Glen 18,508 18,165 343 1.9%"
## [14] " 13 North Park 17,931 18,514 -583 -3.1%"
## [15] " 14 Albany Park 51,542 57,655 -6,113 -10.6%"
## [16] " 15 Portage Park 64,124 65,340 -1,216 -1.9%"
## [17] " 16 Irving Park 53,359 58,643 -5,284 -9.0%"
## [18] " 17 Dunning 41,932 42,164 -232 -0.6%"
## [19] " 18 Montclare 13,426 12,646 780 6.2%"
## [20] " 19 Belmont Cragin 78,743 78,144 599 0.8%"
## [21] " 20 Hermosa 25,010 26,908 -1,898 -7.1%"
## [22] " 21 Avondale 39,262 43,083 -3,821 -8.9%"
## [23] " 22 Logan Square 73,595 82,715 -9,120 -11.0%"
## [24] " 23 Humboldt Park 56,323 65,836 -9,513 -14.4%"
## [25] " 24 West Town 81,432 87,435 -6,003 -6.9%"
## [26] " 25 Austin 98,514 117,527 -19,013 -16.2%"
## [27] " 26 West Garfield Park 18,001 23,019 -5,018 -21.8%"
## [28] " 27 East Garfield Park 20,567 20,881 -314 -1.5%"
## [29] " 28 Near West Side 54,881 46,419 8,462 18.2%"
## [30] " 29 North Lawndale 35,912 41,768 -5,856 -14.0%"
## [31] " 30 South Lawndale 79,288 91,071 -11,783 -12.9%"
## [32] " 31 Lower West Side 35,769 44,031 -8,262 -18.8%"
## [33] " 32 Loop 29,283 16,388 12,895 78.7%"
## [34] " 33 Near South Side 21,390 9,509 11,881 124.9%"
## [35] " 34 Armour Square 13,391 12,032 1,359 11.3%"
## [36] " 35 Douglas 18,238 26,470 -8,232 -31.1%"
## [37] " 36 Oakland 5,918 6,110 -192 -3.1%"
## [38] " 37 Fuller Park 2,876 3,420 -544 -15.9%"
## [39] " 38 Grand Boulevard 21,929 28,006 -6,077 -21.7%"
## [40] " 39 Kenwood 17,841 18,363 -522 -2.8%"
## [41] " 40 Washington Park 11,717 14,146 -2,429 -17.2%"
nnu <- unlist(nni)
nnlist <- c(nnlist,nnu)
nnlist
## [1] ""
## [2] "Num Community Area 2010 2,000 Difference Percentage"
## [3] " 1 Rogers Park 54,991 63,484 -8,493 -13.4%"
## [4] " 2 West Ridge 71,942 73,199 -1,257 -1.7%"
## [5] " 3 Uptown 56,362 63,551 -7,189 -11.3%"
## [6] " 4 Lincoln Square 39,493 44,574 -5,081 -11.4%"
## [7] " 5 North Center 31,867 31,895 -28 -0.1%"
## [8] " 6 Lake View 94,368 94,817 -449 -0.5%"
## [9] " 7 Lincoln Park 64,116 64,320 -204 -0.3%"
## [10] " 8 Near North Side 80,484 72,811 7,673 10.5%"
## [11] " 9 Edison Park 11,187 11,259 -72 -0.6%"
## [12] " 10 Norwood Park 37,023 37,669 -646 -1.7%"
## [13] " 11 Jefferson Park 25,448 25,859 -411 -1.6%"
## [14] " 12 Forest Glen 18,508 18,165 343 1.9%"
## [15] " 13 North Park 17,931 18,514 -583 -3.1%"
## [16] " 14 Albany Park 51,542 57,655 -6,113 -10.6%"
## [17] " 15 Portage Park 64,124 65,340 -1,216 -1.9%"
## [18] " 16 Irving Park 53,359 58,643 -5,284 -9.0%"
## [19] " 17 Dunning 41,932 42,164 -232 -0.6%"
## [20] " 18 Montclare 13,426 12,646 780 6.2%"
## [21] " 19 Belmont Cragin 78,743 78,144 599 0.8%"
## [22] " 20 Hermosa 25,010 26,908 -1,898 -7.1%"
## [23] " 21 Avondale 39,262 43,083 -3,821 -8.9%"
## [24] " 22 Logan Square 73,595 82,715 -9,120 -11.0%"
## [25] " 23 Humboldt Park 56,323 65,836 -9,513 -14.4%"
## [26] " 24 West Town 81,432 87,435 -6,003 -6.9%"
## [27] " 25 Austin 98,514 117,527 -19,013 -16.2%"
## [28] " 26 West Garfield Park 18,001 23,019 -5,018 -21.8%"
## [29] " 27 East Garfield Park 20,567 20,881 -314 -1.5%"
## [30] " 28 Near West Side 54,881 46,419 8,462 18.2%"
## [31] " 29 North Lawndale 35,912 41,768 -5,856 -14.0%"
## [32] " 30 South Lawndale 79,288 91,071 -11,783 -12.9%"
## [33] " 31 Lower West Side 35,769 44,031 -8,262 -18.8%"
## [34] " 32 Loop 29,283 16,388 12,895 78.7%"
## [35] " 33 Near South Side 21,390 9,509 11,881 124.9%"
## [36] " 34 Armour Square 13,391 12,032 1,359 11.3%"
## [37] " 35 Douglas 18,238 26,470 -8,232 -31.1%"
## [38] " 36 Oakland 5,918 6,110 -192 -3.1%"
## [39] " 37 Fuller Park 2,876 3,420 -544 -15.9%"
## [40] " 38 Grand Boulevard 21,929 28,006 -6,077 -21.7%"
## [41] " 39 Kenwood 17,841 18,363 -522 -2.8%"
## [42] " 40 Washington Park 11,717 14,146 -2,429 -17.2%"
nnlist <- ""
for (i in 1:2) {
ppage <- strsplit(pop.dat[[i]],split="\n")
nni <- ppage[[1]]
nni <- nni[-(1:4)]
nnu <- unlist(nni)
nnlist <- c(nnlist,nnu)
}
nnlist
## [1] ""
## [2] "Num Community Area 2010 2,000 Difference Percentage"
## [3] " 1 Rogers Park 54,991 63,484 -8,493 -13.4%"
## [4] " 2 West Ridge 71,942 73,199 -1,257 -1.7%"
## [5] " 3 Uptown 56,362 63,551 -7,189 -11.3%"
## [6] " 4 Lincoln Square 39,493 44,574 -5,081 -11.4%"
## [7] " 5 North Center 31,867 31,895 -28 -0.1%"
## [8] " 6 Lake View 94,368 94,817 -449 -0.5%"
## [9] " 7 Lincoln Park 64,116 64,320 -204 -0.3%"
## [10] " 8 Near North Side 80,484 72,811 7,673 10.5%"
## [11] " 9 Edison Park 11,187 11,259 -72 -0.6%"
## [12] " 10 Norwood Park 37,023 37,669 -646 -1.7%"
## [13] " 11 Jefferson Park 25,448 25,859 -411 -1.6%"
## [14] " 12 Forest Glen 18,508 18,165 343 1.9%"
## [15] " 13 North Park 17,931 18,514 -583 -3.1%"
## [16] " 14 Albany Park 51,542 57,655 -6,113 -10.6%"
## [17] " 15 Portage Park 64,124 65,340 -1,216 -1.9%"
## [18] " 16 Irving Park 53,359 58,643 -5,284 -9.0%"
## [19] " 17 Dunning 41,932 42,164 -232 -0.6%"
## [20] " 18 Montclare 13,426 12,646 780 6.2%"
## [21] " 19 Belmont Cragin 78,743 78,144 599 0.8%"
## [22] " 20 Hermosa 25,010 26,908 -1,898 -7.1%"
## [23] " 21 Avondale 39,262 43,083 -3,821 -8.9%"
## [24] " 22 Logan Square 73,595 82,715 -9,120 -11.0%"
## [25] " 23 Humboldt Park 56,323 65,836 -9,513 -14.4%"
## [26] " 24 West Town 81,432 87,435 -6,003 -6.9%"
## [27] " 25 Austin 98,514 117,527 -19,013 -16.2%"
## [28] " 26 West Garfield Park 18,001 23,019 -5,018 -21.8%"
## [29] " 27 East Garfield Park 20,567 20,881 -314 -1.5%"
## [30] " 28 Near West Side 54,881 46,419 8,462 18.2%"
## [31] " 29 North Lawndale 35,912 41,768 -5,856 -14.0%"
## [32] " 30 South Lawndale 79,288 91,071 -11,783 -12.9%"
## [33] " 31 Lower West Side 35,769 44,031 -8,262 -18.8%"
## [34] " 32 Loop 29,283 16,388 12,895 78.7%"
## [35] " 33 Near South Side 21,390 9,509 11,881 124.9%"
## [36] " 34 Armour Square 13,391 12,032 1,359 11.3%"
## [37] " 35 Douglas 18,238 26,470 -8,232 -31.1%"
## [38] " 36 Oakland 5,918 6,110 -192 -3.1%"
## [39] " 37 Fuller Park 2,876 3,420 -544 -15.9%"
## [40] " 38 Grand Boulevard 21,929 28,006 -6,077 -21.7%"
## [41] " 39 Kenwood 17,841 18,363 -522 -2.8%"
## [42] " 40 Washington Park 11,717 14,146 -2,429 -17.2%"
## [43] "Num Community Area 2010 2,000 Difference Percentage"
## [44] " 41 Hyde Park 25,681 29,920 -4,239 -14.2%"
## [45] " 42 Woodlawn 25,983 27,086 -1,103 -4.1%"
## [46] " 43 South Shore 49,767 61,556 -11,789 -19.2%"
## [47] " 44 Chatham 31,028 37,275 -6,247 -16.8%"
## [48] " 45 Avalon Park 10,185 11,147 -962 -8.6%"
## [49] " 46 South Chicago 31,198 38,596 -7,398 -19.2%"
## [50] " 47 Burnside 2,916 3,294 -378 -11.5%"
## [51] " 48 Calumet Heights 13,812 15,974 -2,162 -13.5%"
## [52] " 49 Roseland 44,619 52,723 -8,104 -15.4%"
## [53] " 50 Pullman 7,325 8,921 -1,596 -17.9%"
## [54] " 51 South Deering 15,109 16,990 -1,881 -11.1%"
## [55] " 52 East Side 23,042 23,653 -611 -2.6%"
## [56] " 53 West Pullman 29,651 36,649 -6,998 -19.1%"
## [57] " 54 Riverdale 6,482 9,809 -3,327 -33.9%"
## [58] " 55 Hegewisch 9,426 9,781 -355 -3.6%"
## [59] " 56 Garfield Ridge 34,513 36,101 -1,588 -4.4%"
## [60] " 57 Archer Heights 13,393 12,644 749 5.9%"
## [61] " 58 Brighton Park 45,368 44,912 456 1.0%"
## [62] " 59 McKinley Park 15,612 15,962 -350 -2.2%"
## [63] " 60 Bridgeport 31,977 33,694 -1,717 -5.1%"
## [64] " 61 New City 44,377 51,721 -7,344 -14.2%"
## [65] " 62 West Elsdon 18,109 15,921 2,188 13.7%"
## [66] " 63 Gage Park 39,894 39,193 701 1.8%"
## [67] " 64 Clearing 23,139 22,331 808 3.6%"
## [68] " 65 West Lawn 33,355 29,235 4,120 14.1%"
## [69] " 66 Chicago Lawn 55,628 61,412 -5,784 -9.4%"
## [70] " 67 West Englewood 35,505 45,282 -9,777 -21.6%"
## [71] " 68 Englewood 30,654 40,222 -9,568 -23.8%"
## [72] " 69 Greater Grand Crossing 32,602 38,619 -6,017 -15.6%"
## [73] " 70 Ashburn 41,081 39,584 1,497 3.8%"
## [74] " 71 Auburn Gresham 48,743 55,928 -7,185 -12.8%"
## [75] " 72 Beverly 20,034 21,992 -1,958 -8.9%"
## [76] " 73 Washington Heights 26,493 29,843 -3,350 -11.2%"
## [77] " 74 Mount Greenwood 19,093 18,820 273 1.5%"
## [78] " 75 Morgan Park 22,544 25,226 -2,682 -10.6%"
## [79] " 76 O'Hare 12,756 11,956 800 6.7%"
## [80] " 77 Edgewater 56,521 62,198 -5,677 -9.1%"
## [81] " Total 2,695,598 2,896,016 -200,418 -6.9%"
nnlist <- nnlist[2:(length(nnlist)-1)]
nnpop <- vector(mode="numeric",length=length(nnlist))
for (i in (1:length(nnlist))) {
popchar <- substr(nnlist[i],start=27,stop=39)
popval <- as.numeric(gsub(",","",popchar))
nnpop[i] <- popval
}
## Warning: NAs introduced by coercion
nnpop
## [1] 2010 54991 71942 56362 39493 31867 94368 64116 80484 11187 37023 25448
## [13] 18508 17931 51542 64124 53359 41932 13426 78743 25010 39262 73595 56323
## [25] 81432 98514 18001 20567 54881 35912 79288 35769 29283 21390 13391 18238
## [37] 5918 2876 21929 17841 11717 2010 25 25 49 31 10 31
## [49] 2 13 44 7 15 23 29 6 9 34 13 45
## [61] 15 31 44 18 39 23 33 55 35 30 NA 41
## [73] 48 20 26 19 22 12 56
nnid <- (1:length(nnlist))
nnid
## [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
## [26] 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
## [51] 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
## [76] 76 77 78 79
neighpop <- data.frame(as.integer(nnid),nnpop)
names(neighpop) <- c("NID","POP2010")
head(neighpop)
## NID POP2010
## 1 1 2010
## 2 2 54991
## 3 3 71942
## 4 4 56362
## 5 5 39493
## 6 6 31867
chicago.comm <- left_join(chicago.comm,neighpop, by = c("area_num_1" = "NID"))
head(chicago.comm)
## Simple feature collection with 6 features and 7 fields
## Geometry type: MULTIPOLYGON
## Dimension: XY
## Bounding box: xmin: 441141.3 ymin: 4642477 xmax: 447735.4 ymax: 4652556
## Projected CRS: WGS 84 / UTM zone 16N
## # A tibble: 6 × 8
## community shape_area area_num_1 area_numbe shape_len geometry
## <chr> <chr> <int> <chr> <chr> <MULTIPOLYGON [m]>
## 1 ROGERS P… 51259902.… 1 1 34052.39… (((445789.6 4649780, 445…
## 2 WEST RID… 98429094.… 2 2 43020.68… (((443315.8 4652166, 443…
## 3 UPTOWN 65095642.… 3 3 46972.79… (((446874.2 4644957, 446…
## 4 LINCOLN … 71352328.… 4 4 36624.60… (((444126.1 4647343, 444…
## 5 NORTH CE… 57054167.… 5 5 31391.66… (((444174.4 4642484, 444…
## 6 LAKE VIEW 87214799.… 6 6 51973.09… (((446874.2 4644957, 446…
## # ℹ 2 more variables: AGG.COUNT <int>, POP2010 <dbl>
chicago.comm <- chicago.comm %>% mutate(vehpcap = (AGG.COUNT / POP2010) * 1000)
head(chicago.comm)
## Simple feature collection with 6 features and 8 fields
## Geometry type: MULTIPOLYGON
## Dimension: XY
## Bounding box: xmin: 441141.3 ymin: 4642477 xmax: 447735.4 ymax: 4652556
## Projected CRS: WGS 84 / UTM zone 16N
## # A tibble: 6 × 9
## community shape_area area_num_1 area_numbe shape_len geometry
## <chr> <chr> <int> <chr> <chr> <MULTIPOLYGON [m]>
## 1 ROGERS P… 51259902.… 1 1 34052.39… (((445789.6 4649780, 445…
## 2 WEST RID… 98429094.… 2 2 43020.68… (((443315.8 4652166, 443…
## 3 UPTOWN 65095642.… 3 3 46972.79… (((446874.2 4644957, 446…
## 4 LINCOLN … 71352328.… 4 4 36624.60… (((444126.1 4647343, 444…
## 5 NORTH CE… 57054167.… 5 5 31391.66… (((444174.4 4642484, 444…
## 6 LAKE VIEW 87214799.… 6 6 51973.09… (((446874.2 4644957, 446…
## # ℹ 3 more variables: AGG.COUNT <int>, POP2010 <dbl>, vehpcap <dbl>
tm_shape(chicago.comm) +
tm_polygons("vehpcap")
st_write(chicago.comm,"chicago_vehicles_",driver="ESRI Shapefile")
## Writing layer `chicago_vehicles_' to data source
## `chicago_vehicles_' using driver `ESRI Shapefile'
## Writing 77 features with 8 fields and geometry type Multi Polygon.
Reference
https://spatialanalysis.github.io/handsonspatialdata/spatial-data-handling.html