library(sf)
## Linking to GEOS 3.13.1, GDAL 3.11.0, PROJ 9.6.0; sf_use_s2() is TRUE
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 3.5.2 ✔ 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(dplyr)
library(stringr)
library(tmap)
library(tigris)
## To enable caching of data, set `options(tigris_use_cache = TRUE)`
## in your R script or .Rprofile.
library(purrr)
attrs <- read.csv('pittsboro_attributes.csv')
geom <- st_read('pittsboro_geometry.geojson')
## Reading layer `pittsboro_geometry' from data source
## `C:\Users\xfitten3\OneDrive - Georgia Institute of Technology\Desktop\Urban_A\pittsboro_geometry.geojson'
## using driver `GeoJSON'
## Simple feature collection with 93 features and 1 field
## Geometry type: POINT
## Dimension: XY
## Bounding box: xmin: -79.23351 ymin: 35.64281 xmax: -79.03366 ymax: 35.78238
## Geodetic CRS: WGS 84
pboro <- geom %>% left_join(attrs, by = 'row_id')
####Tidying Data####
Remove Duplicated Rows
pboro2 <- pboro %>%
distinct(places.id, .keep_all = TRUE)
print(nrow(pboro))
## [1] 93
print(nrow(pboro2))
## [1] 41
#Flatten/unnest list-columns#
##note: I had to figure out how to export to make rmd better than mini 1 #so this is what I would have done:
#data_all_sf <- data_all_sf %>%
#mutate(place.id = places.types %>%
#map_chr(., ~str_c(.x, collapse = ','))) # print(data_all_sf$place.id)
removena
library(purrr)
print(pboro2 %>% map_dbl(., ~sum(is.na(.x))))
## row_id places.id
## 0 0
## places.types places.formattedAddress
## 0 0
## places.rating places.userRatingCount
## 7 7
## places.priceLevel places.displayName.text
## 36 0
## places.displayName.languageCode geometry
## 0 0
pboro3 <- pboro2 %>%
filter(!is.na(places.rating))
print(length(pboro2$places.rating))
## [1] 41
print(length(pboro3$places.rating))
## [1] 34
remove poi outside of city
#creating a status column for later (added after)
pboro3 <- pboro3 %>% mutate(status = ifelse(str_detect(places.types, 'park'),'park','coffee shop'))
library(tmap)
library(sf)
pitts <- tigris::places('NC', progress_bar = FALSE) %>%
filter(NAME == 'Pittsboro') %>% st_transform(4326)
## Retrieving data for the year 2024
poi_sf <- pboro3 %>% st_as_sf(coords = geometry)
tmap_mode('view')
## ℹ tmap modes "plot" - "view"
## ℹ toggle with `tmap::ttm()`
## This message is displayed once per session.
tm_shape(pitts) +
tm_borders() +
tm_fill('green') +
tm_shape(poi_sf) +
tm_dots(col = 'blue', size = .74)
poi_sf_in <- poi_sf[ st_within(poi_sf, pitts, sparse = FALSE), ]
tmap_mode('view')
## ℹ tmap modes "plot" - "view"
tm_shape(pitts) +
tm_borders() +
tm_fill('green') +
tm_shape(poi_sf_in) +
tm_dots(col = 'blue', size = .74)
coffemap <- tmap_mode('view')
## ℹ tmap modes "plot" - "view"
tm_shape(pitts) +
tm_borders() +
tm_fill('green') +
tm_shape(poi_sf_in) +
tm_dots(col = 'status', size = .74, palette = 'BrBG')
##
## ── tmap v3 code detected ───────────────────────────────────────────────────────
## [v3->v4] `tm_tm_dots()`: 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_dots()`: use 'fill' for the fill color of polygons/symbols
## (instead of 'col'), and 'col' for the outlines (instead of 'border.col').[cols4all] color palettes: use palettes from the R package cols4all. Run
## `cols4all::c4a_gui()` to explore them. The old palette name "BrBG" is named
## "brewer.br_bg"Multiple palettes called "br_bg" found: "brewer.br_bg", "matplotlib.br_bg". The first one, "brewer.br_bg", is returned.
print(coffemap)
## [1] "view"
print(poi_sf_in)
## Simple feature collection with 17 features and 10 fields
## Geometry type: POINT
## Dimension: XY
## Bounding box: xmin: -79.19758 ymin: 35.71045 xmax: -79.15638 ymax: 35.75771
## Geodetic CRS: WGS 84
## First 10 features:
## row_id places.id
## 2 2 ChIJD9duL8O5rIkRpPZ9NsMRMwo
## 3 4 ChIJV8VTe8a5rIkR24j_dXrWxHs
## 4 6 ChIJYWCQC9i5rIkRJiY6VebMcIU
## 5 7 ChIJu4lztse5rIkR6YUkxyaBftM
## 7 9 ChIJJyLw1DS5rIkRGwyS0pupWqk
## 8 10 ChIJHwnMC7i5rIkRUWUWM8TLSBM
## 9 11 ChIJvf7q2re5rIkRHiZjifl7EOI
## 10 12 ChIJu6jDgYq5rIkRPONcJkn-xdM
## 11 13 ChIJLZvbk8m5rIkRATWC51thhU4
## 12 14 ChIJmfs8w7e5rIkRzqAJsIfkyYM
## places.types
## 2 park, tourist_attraction, point_of_interest, establishment
## 3 park, point_of_interest, establishment
## 4 hiking_area, park, sports_activity_location, point_of_interest, establishment
## 5 bakery, coffee_shop, cafe, food_store, point_of_interest, store, food, establishment
## 7 coffee_shop, cafe, bar, wholesaler, food_store, event_venue, restaurant, point_of_interest, store, food, establishment
## 8 garden, park, local_government_office, government_office, point_of_interest, establishment
## 9 park, point_of_interest, establishment
## 10 coffee_shop, cafe, food_store, point_of_interest, store, food, establishment
## 11 park, tourist_attraction, point_of_interest, establishment
## 12 coffee_shop, tea_house, cafe, food_store, point_of_interest, store, food, establishment
## places.formattedAddress places.rating
## 2 529 NC-902, Pittsboro, NC 27312, USA 4.4
## 3 290 Pittsboro Elem School Rd, Pittsboro, NC 27312, USA 4.4
## 4 Pittsboro, NC 27312, USA 4.3
## 5 35 W Chatham St, Pittsboro, NC 27312, USA 4.5
## 7 39 West St, Pittsboro, NC 27312, USA 4.5
## 8 1192 U.S. 64 West Business Suite 400, Pittsboro, NC 27312, USA 5.0
## 9 110 Hillsboro St, Pittsboro, NC 27312, USA 4.7
## 10 220 Lorax Ln, Pittsboro, NC 27312, USA 4.9
## 11 309 Credle St, Pittsboro, NC 27312, USA 4.4
## 12 439 Hillsboro St, Pittsboro, NC 27312, USA 4.7
## places.userRatingCount places.priceLevel
## 2 80 <NA>
## 3 16 <NA>
## 4 4 <NA>
## 5 110 PRICE_LEVEL_INEXPENSIVE
## 7 125 <NA>
## 8 3 <NA>
## 9 6 <NA>
## 10 7 <NA>
## 11 113 <NA>
## 12 214 PRICE_LEVEL_INEXPENSIVE
## places.displayName.text
## 2 Town Lake Park
## 3 McClenahan Street Park
## 4 Robeson Creek Greenway
## 5 Willy's Cinnamon Rolls, Etc.
## 7 Havoc Brewing Company
## 8 N.C. Cooperative Extension, Chatham County Center
## 9 Page Vernon Park
## 10 Metal Brixx Cafe
## 11 Kiwanis Park
## 12 Davenport's Café Diem
## places.displayName.languageCode geometry status
## 2 en POINT (-79.18693 35.71268) park
## 3 en POINT (-79.18238 35.71822) park
## 4 en POINT (-79.17277 35.71628) park
## 5 en POINT (-79.17879 35.71886) coffee shop
## 7 en POINT (-79.17804 35.72004) coffee shop
## 8 en POINT (-79.19758 35.72394) park
## 9 en POINT (-79.17682 35.72194) park
## 10 en POINT (-79.15638 35.71045) coffee shop
## 11 en POINT (-79.1795 35.72494) park
## 12 en POINT (-79.17696 35.72667) coffee shop
####report findings####
summary <- pboro3 %>%
group_by(status) %>%
summarise(mean_score = mean(places.rating))
print(summary)
## Simple feature collection with 2 features and 2 fields
## Geometry type: MULTIPOINT
## Dimension: XY
## Bounding box: xmin: -79.23351 ymin: 35.64281 xmax: -79.03366 ymax: 35.7735
## Geodetic CRS: WGS 84
## # A tibble: 2 × 3
## status mean_score geometry
## <chr> <dbl> <MULTIPOINT [°]>
## 1 coffee shop 4.42 ((-79.16711 35.74449), (-79.16852 35.75364), (-79.1563…
## 2 park 4.55 ((-79.23351 35.71462), (-79.17435 35.74373), (-79.1638…
Okay, so I chose a vapid topic for my places. I took a look to see where parks and coffee shops were located in this small town in pittsboro, NC.
There is a higher concentration of higher rated coffee shops in the southern part of the city. Since I chose Coffee, the price level for all of them is going to be inexpensive. beyond the clustering in the south west park of the city, there are no parks nor coffee shops in the north eastern part. when we examine the map as open streets, we see there’s a natural area adjacent to this part, so i guess you could call that a park. But, I’m curious about the influence of that area on this part of the city. wouldn’t you assume that there’d be coffee shops for early morning hikers? The mean score for the two things are about the same. My aunt lives in this city which is why I chose it, and I now have some recommendations for her. Aromatic Roasters