rm(list = ls())
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.3 ✔ readr 2.1.4
## ✔ forcats 1.0.0 ✔ stringr 1.5.0
## ✔ ggplot2 3.4.3 ✔ tibble 3.2.1
## ✔ lubridate 1.9.2 ✔ tidyr 1.3.0
## ✔ purrr 1.0.2
## ── 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(sf)
## Linking to GEOS 3.11.2, GDAL 3.6.2, PROJ 9.2.0; sf_use_s2() is TRUE
library(here)
## here() starts at D:/Storage/Master/23fall/CP6088 Intro to Urban Analytics/6088mini1
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)
library(dplyr)
library(jsonlite)
##
## 载入程辑包:'jsonlite'
##
## The following object is masked from 'package:purrr':
##
## flatten
library(purrr)
library(tidycensus)
getwd()
## [1] "D:/Storage/Master/23fall/CP6088 Intro to Urban Analytics/6088mini1"
setwd('D:/Storage/Master/23fall/CP6088 Intro to Urban Analytics/6088mini1')
yelp_all1<-read_rds(file='6088yelp_all1')
ready4tidy<-yelp_all1
yelp_dup <- ready4tidy %>%
distinct(id, .keep_all=T)
glue::glue("Before dealing with duplicates, there were {nrow(ready4tidy)} rows. After dealing with duplicates, there are {nrow(yelp_dup)} rows") %>%
print()
## Before dealing with duplicates, there were 1797 rows. After dealing with duplicates, there are 415 rows
yelp_flat <- yelp_dup %>%
jsonlite::flatten() %>%
as_tibble()
yelp_flat$coordinates %>% head()
## Warning: Unknown or uninitialised column: `coordinates`.
## NULL
# multiple variables in the "categories" column
# Custom function that takes the data frame in "categories" column in Yelp data
# and returns a character vector
concate_list <- function(x){
titles <- x[["title"]] %>% str_c(collapse = ", ")
return(titles)
}
yelp_concat<-yelp_flat%>%
mutate(transactions = transactions %>%
map_chr(., function(x) str_c(x, collapse=", ")),
location.display_address = location.display_address %>%
map_chr(., function(x) str_c(x, collapse=", ")),
categories = categories %>% map_chr(concate_list))
str(yelp_flat$categories)
## List of 415
## $ :'data.frame': 3 obs. of 2 variables:
## ..$ alias: chr [1:3] "desserts" "tradamerican" "sandwiches"
## ..$ title: chr [1:3] "Desserts" "American (Traditional)" "Sandwiches"
## $ :'data.frame': 1 obs. of 2 variables:
## ..$ alias: chr "coffeeroasteries"
## ..$ title: chr "Coffee Roasteries"
## $ :'data.frame': 2 obs. of 2 variables:
## ..$ alias: chr [1:2] "servicestations" "convenience"
## ..$ title: chr [1:2] "Gas Stations" "Convenience Stores"
## $ :'data.frame': 1 obs. of 2 variables:
## ..$ alias: chr "icecream"
## ..$ title: chr "Ice Cream & Frozen Yogurt"
## $ :'data.frame': 2 obs. of 2 variables:
## ..$ alias: chr [1:2] "pizza" "foodtrucks"
## ..$ title: chr [1:2] "Pizza" "Food Trucks"
## $ :'data.frame': 2 obs. of 2 variables:
## ..$ alias: chr [1:2] "venues" "tea"
## ..$ title: chr [1:2] "Venues & Event Spaces" "Tea Rooms"
## $ :'data.frame': 3 obs. of 2 variables:
## ..$ alias: chr [1:3] "bakeries" "customcakes" "cupcakes"
## ..$ title: chr [1:3] "Bakeries" "Custom Cakes" "Cupcakes"
## $ :'data.frame': 2 obs. of 2 variables:
## ..$ alias: chr [1:2] "desserts" "icecream"
## ..$ title: chr [1:2] "Desserts" "Ice Cream & Frozen Yogurt"
## $ :'data.frame': 3 obs. of 2 variables:
## ..$ alias: chr [1:3] "hotdogs" "icecream" "burgers"
## ..$ title: chr [1:3] "Fast Food" "Ice Cream & Frozen Yogurt" "Burgers"
## $ :'data.frame': 2 obs. of 2 variables:
## ..$ alias: chr [1:2] "coffee" "donuts"
## ..$ title: chr [1:2] "Coffee & Tea" "Donuts"
## $ :'data.frame': 1 obs. of 2 variables:
## ..$ alias: chr "icecream"
## ..$ title: chr "Ice Cream & Frozen Yogurt"
## $ :'data.frame': 3 obs. of 2 variables:
## ..$ alias: chr [1:3] "drugstores" "pharmacy" "convenience"
## ..$ title: chr [1:3] "Drugstores" "Pharmacy" "Convenience Stores"
## $ :'data.frame': 1 obs. of 2 variables:
## ..$ alias: chr "beer_and_wine"
## ..$ title: chr "Beer, Wine & Spirits"
## $ :'data.frame': 1 obs. of 2 variables:
## ..$ alias: chr "grocery"
## ..$ title: chr "Grocery"
## $ :'data.frame': 1 obs. of 2 variables:
## ..$ alias: chr "winetastingroom"
## ..$ title: chr "Wine Tasting Room"
## $ :'data.frame': 1 obs. of 2 variables:
## ..$ alias: chr "bakeries"
## ..$ title: chr "Bakeries"
## $ :'data.frame': 3 obs. of 2 variables:
## ..$ alias: chr [1:3] "newamerican" "bars" "fooddeliveryservices"
## ..$ title: chr [1:3] "American (New)" "Bars" "Food Delivery Services"
## $ :'data.frame': 1 obs. of 2 variables:
## ..$ alias: chr "breweries"
## ..$ title: chr "Breweries"
## $ :'data.frame': 3 obs. of 2 variables:
## ..$ alias: chr [1:3] "chickenshop" "hotdogs" "icecream"
## ..$ title: chr [1:3] "Chicken Shop" "Fast Food" "Ice Cream & Frozen Yogurt"
## $ :'data.frame': 3 obs. of 2 variables:
## ..$ alias: chr [1:3] "hawaiian" "poke" "icecream"
## ..$ title: chr [1:3] "Hawaiian" "Poke" "Ice Cream & Frozen Yogurt"
## $ :'data.frame': 3 obs. of 2 variables:
## ..$ alias: chr [1:3] "coffee" "juicebars" "womenscloth"
## ..$ title: chr [1:3] "Coffee & Tea" "Juice Bars & Smoothies" "Women's Clothing"
## $ :'data.frame': 3 obs. of 2 variables:
## ..$ alias: chr [1:3] "seafood" "bars" "desserts"
## ..$ title: chr [1:3] "Seafood" "Bars" "Desserts"
## $ :'data.frame': 2 obs. of 2 variables:
## ..$ alias: chr [1:2] "hawaiian" "poke"
## ..$ title: chr [1:2] "Hawaiian" "Poke"
## $ :'data.frame': 2 obs. of 2 variables:
## ..$ alias: chr [1:2] "mexican" "intlgrocery"
## ..$ title: chr [1:2] "Mexican" "International Grocery"
## $ :'data.frame': 3 obs. of 2 variables:
## ..$ alias: chr [1:3] "cafes" "coffee" "juicebars"
## ..$ title: chr [1:3] "Cafes" "Coffee & Tea" "Juice Bars & Smoothies"
## $ :'data.frame': 3 obs. of 2 variables:
## ..$ alias: chr [1:3] "foodtrucks" "empanadas" "argentine"
## ..$ title: chr [1:3] "Food Trucks" "Empanadas" "Argentine"
## $ :'data.frame': 3 obs. of 2 variables:
## ..$ alias: chr [1:3] "sandwiches" "juicebars" "asianfusion"
## ..$ title: chr [1:3] "Sandwiches" "Juice Bars & Smoothies" "Asian Fusion"
## $ :'data.frame': 3 obs. of 2 variables:
## ..$ alias: chr [1:3] "icecream" "wine_bars" "cocktailbars"
## ..$ title: chr [1:3] "Ice Cream & Frozen Yogurt" "Wine Bars" "Cocktail Bars"
## $ :'data.frame': 3 obs. of 2 variables:
## ..$ alias: chr [1:3] "bubbletea" "coffee" "acaibowls"
## ..$ title: chr [1:3] "Bubble Tea" "Coffee & Tea" "Acai Bowls"
## $ :'data.frame': 1 obs. of 2 variables:
## ..$ alias: chr "desserts"
## ..$ title: chr "Desserts"
## $ :'data.frame': 2 obs. of 2 variables:
## ..$ alias: chr [1:2] "icecream" "desserts"
## ..$ title: chr [1:2] "Ice Cream & Frozen Yogurt" "Desserts"
## $ :'data.frame': 3 obs. of 2 variables:
## ..$ alias: chr [1:3] "bbq" "tradamerican" "desserts"
## ..$ title: chr [1:3] "Barbeque" "American (Traditional)" "Desserts"
## $ :'data.frame': 2 obs. of 2 variables:
## ..$ alias: chr [1:2] "raw_food" "juicebars"
## ..$ title: chr [1:2] "Live/Raw Food" "Juice Bars & Smoothies"
## $ :'data.frame': 3 obs. of 2 variables:
## ..$ alias: chr [1:3] "bakeries" "coffee" "donuts"
## ..$ title: chr [1:3] "Bakeries" "Coffee & Tea" "Donuts"
## $ :'data.frame': 3 obs. of 2 variables:
## ..$ alias: chr [1:3] "bakeries" "foodtrucks" "icecream"
## ..$ title: chr [1:3] "Bakeries" "Food Trucks" "Ice Cream & Frozen Yogurt"
## $ :'data.frame': 2 obs. of 2 variables:
## ..$ alias: chr [1:2] "markets" "herbsandspices"
## ..$ title: chr [1:2] "Fruits & Veggies" "Herbs & Spices"
## $ :'data.frame': 1 obs. of 2 variables:
## ..$ alias: chr "fooddeliveryservices"
## ..$ title: chr "Food Delivery Services"
## $ :'data.frame': 1 obs. of 2 variables:
## ..$ alias: chr "coffee"
## ..$ title: chr "Coffee & Tea"
## $ :'data.frame': 1 obs. of 2 variables:
## ..$ alias: chr "fooddeliveryservices"
## ..$ title: chr "Food Delivery Services"
## $ :'data.frame': 1 obs. of 2 variables:
## ..$ alias: chr "fooddeliveryservices"
## ..$ title: chr "Food Delivery Services"
## $ :'data.frame': 2 obs. of 2 variables:
## ..$ alias: chr [1:2] "juicebars" "sandwiches"
## ..$ title: chr [1:2] "Juice Bars & Smoothies" "Sandwiches"
## $ :'data.frame': 3 obs. of 2 variables:
## ..$ alias: chr [1:3] "pizza" "salad" "beer_and_wine"
## ..$ title: chr [1:3] "Pizza" "Salad" "Beer, Wine & Spirits"
## $ :'data.frame': 2 obs. of 2 variables:
## ..$ alias: chr [1:2] "coffee" "foodtrucks"
## ..$ title: chr [1:2] "Coffee & Tea" "Food Trucks"
## $ :'data.frame': 1 obs. of 2 variables:
## ..$ alias: chr "grocery"
## ..$ title: chr "Grocery"
## $ :'data.frame': 1 obs. of 2 variables:
## ..$ alias: chr "intlgrocery"
## ..$ title: chr "International Grocery"
## $ :'data.frame': 1 obs. of 2 variables:
## ..$ alias: chr "fooddeliveryservices"
## ..$ title: chr "Food Delivery Services"
## $ :'data.frame': 2 obs. of 2 variables:
## ..$ alias: chr [1:2] "icecream" "desserts"
## ..$ title: chr [1:2] "Ice Cream & Frozen Yogurt" "Desserts"
## $ :'data.frame': 2 obs. of 2 variables:
## ..$ alias: chr [1:2] "fooddeliveryservices" "cheesesteaks"
## ..$ title: chr [1:2] "Food Delivery Services" "Cheesesteaks"
## $ :'data.frame': 1 obs. of 2 variables:
## ..$ alias: chr "gourmet"
## ..$ title: chr "Specialty Food"
## $ :'data.frame': 1 obs. of 2 variables:
## ..$ alias: chr "icecream"
## ..$ title: chr "Ice Cream & Frozen Yogurt"
## $ :'data.frame': 2 obs. of 2 variables:
## ..$ alias: chr [1:2] "gourmet" "kitchenandbath"
## ..$ title: chr [1:2] "Specialty Food" "Kitchen & Bath"
## $ :'data.frame': 2 obs. of 2 variables:
## ..$ alias: chr [1:2] "bakeries" "desserts"
## ..$ title: chr [1:2] "Bakeries" "Desserts"
## $ :'data.frame': 3 obs. of 2 variables:
## ..$ alias: chr [1:3] "hotdogs" "burgers" "coffee"
## ..$ title: chr [1:3] "Fast Food" "Burgers" "Coffee & Tea"
## $ :'data.frame': 2 obs. of 2 variables:
## ..$ alias: chr [1:2] "desserts" "bakeries"
## ..$ title: chr [1:2] "Desserts" "Bakeries"
## $ :'data.frame': 1 obs. of 2 variables:
## ..$ alias: chr "grocery"
## ..$ title: chr "Grocery"
## $ :'data.frame': 3 obs. of 2 variables:
## ..$ alias: chr [1:3] "grocery" "markets" "organic_stores"
## ..$ title: chr [1:3] "Grocery" "Fruits & Veggies" "Organic Stores"
## $ :'data.frame': 3 obs. of 2 variables:
## ..$ alias: chr [1:3] "hotdogs" "coffee" "burgers"
## ..$ title: chr [1:3] "Fast Food" "Coffee & Tea" "Burgers"
## $ :'data.frame': 3 obs. of 2 variables:
## ..$ alias: chr [1:3] "grocery" "healthmarkets" "organic_stores"
## ..$ title: chr [1:3] "Grocery" "Health Markets" "Organic Stores"
## $ :'data.frame': 1 obs. of 2 variables:
## ..$ alias: chr "farmersmarket"
## ..$ title: chr "Farmers Market"
## $ :'data.frame': 2 obs. of 2 variables:
## ..$ alias: chr [1:2] "deptstores" "grocery"
## ..$ title: chr [1:2] "Department Stores" "Grocery"
## $ :'data.frame': 3 obs. of 2 variables:
## ..$ alias: chr [1:3] "bbq" "foodtrucks" "burgers"
## ..$ title: chr [1:3] "Barbeque" "Food Trucks" "Burgers"
## $ :'data.frame': 1 obs. of 2 variables:
## ..$ alias: chr "beer_and_wine"
## ..$ title: chr "Beer, Wine & Spirits"
## $ :'data.frame': 2 obs. of 2 variables:
## ..$ alias: chr [1:2] "foodtrucks" "sandwiches"
## ..$ title: chr [1:2] "Food Trucks" "Sandwiches"
## $ :'data.frame': 1 obs. of 2 variables:
## ..$ alias: chr "bakeries"
## ..$ title: chr "Bakeries"
## $ :'data.frame': 1 obs. of 2 variables:
## ..$ alias: chr "healthmarkets"
## ..$ title: chr "Health Markets"
## $ :'data.frame': 3 obs. of 2 variables:
## ..$ alias: chr [1:3] "desserts" "seafood" "cocktailbars"
## ..$ title: chr [1:3] "Desserts" "Seafood" "Cocktail Bars"
## $ :'data.frame': 3 obs. of 2 variables:
## ..$ alias: chr [1:3] "icecream" "hotdogs" "burgers"
## ..$ title: chr [1:3] "Ice Cream & Frozen Yogurt" "Fast Food" "Burgers"
## $ :'data.frame': 1 obs. of 2 variables:
## ..$ alias: chr "beer_and_wine"
## ..$ title: chr "Beer, Wine & Spirits"
## $ :'data.frame': 3 obs. of 2 variables:
## ..$ alias: chr [1:3] "fooddeliveryservices" "catering" "personalchefs"
## ..$ title: chr [1:3] "Food Delivery Services" "Caterers" "Personal Chefs"
## $ :'data.frame': 1 obs. of 2 variables:
## ..$ alias: chr "beer_and_wine"
## ..$ title: chr "Beer, Wine & Spirits"
## $ :'data.frame': 2 obs. of 2 variables:
## ..$ alias: chr [1:2] "coffee" "donuts"
## ..$ title: chr [1:2] "Coffee & Tea" "Donuts"
## $ :'data.frame': 1 obs. of 2 variables:
## ..$ alias: chr "coffee"
## ..$ title: chr "Coffee & Tea"
## $ :'data.frame': 2 obs. of 2 variables:
## ..$ alias: chr [1:2] "juicebars" "healthmarkets"
## ..$ title: chr [1:2] "Juice Bars & Smoothies" "Health Markets"
## $ :'data.frame': 3 obs. of 2 variables:
## ..$ alias: chr [1:3] "coffee" "breakfast_brunch" "juicebars"
## ..$ title: chr [1:3] "Coffee & Tea" "Breakfast & Brunch" "Juice Bars & Smoothies"
## $ :'data.frame': 3 obs. of 2 variables:
## ..$ alias: chr [1:3] "farmersmarket" "farms" "csa"
## ..$ title: chr [1:3] "Farmers Market" "Farms" "CSA"
## $ :'data.frame': 2 obs. of 2 variables:
## ..$ alias: chr [1:2] "servicestations" "convenience"
## ..$ title: chr [1:2] "Gas Stations" "Convenience Stores"
## $ :'data.frame': 3 obs. of 2 variables:
## ..$ alias: chr [1:3] "burgers" "hotdogs" "coffee"
## ..$ title: chr [1:3] "Burgers" "Fast Food" "Coffee & Tea"
## $ :'data.frame': 2 obs. of 2 variables:
## ..$ alias: chr [1:2] "servicestations" "convenience"
## ..$ title: chr [1:2] "Gas Stations" "Convenience Stores"
## $ :'data.frame': 3 obs. of 2 variables:
## ..$ alias: chr [1:3] "icecream" "desserts" "foodtrucks"
## ..$ title: chr [1:3] "Ice Cream & Frozen Yogurt" "Desserts" "Food Trucks"
## $ :'data.frame': 2 obs. of 2 variables:
## ..$ alias: chr [1:2] "coffee" "cafes"
## ..$ title: chr [1:2] "Coffee & Tea" "Cafes"
## $ :'data.frame': 2 obs. of 2 variables:
## ..$ alias: chr [1:2] "servicestations" "convenience"
## ..$ title: chr [1:2] "Gas Stations" "Convenience Stores"
## $ :'data.frame': 1 obs. of 2 variables:
## ..$ alias: chr "beer_and_wine"
## ..$ title: chr "Beer, Wine & Spirits"
## $ :'data.frame': 2 obs. of 2 variables:
## ..$ alias: chr [1:2] "vitaminssupplements" "healthmarkets"
## ..$ title: chr [1:2] "Vitamins & Supplements" "Health Markets"
## $ :'data.frame': 2 obs. of 2 variables:
## ..$ alias: chr [1:2] "servicestations" "convenience"
## ..$ title: chr [1:2] "Gas Stations" "Convenience Stores"
## $ :'data.frame': 3 obs. of 2 variables:
## ..$ alias: chr [1:3] "drugstores" "pharmacy" "convenience"
## ..$ title: chr [1:3] "Drugstores" "Pharmacy" "Convenience Stores"
## $ :'data.frame': 3 obs. of 2 variables:
## ..$ alias: chr [1:3] "psychic_astrology" "tea" "reiki"
## ..$ title: chr [1:3] "Supernatural Readings" "Tea Rooms" "Reiki"
## $ :'data.frame': 2 obs. of 2 variables:
## ..$ alias: chr [1:2] "foodtrucks" "juicebars"
## ..$ title: chr [1:2] "Food Trucks" "Juice Bars & Smoothies"
## $ :'data.frame': 3 obs. of 2 variables:
## ..$ alias: chr [1:3] "bakeries" "desserts" "cupcakes"
## ..$ title: chr [1:3] "Bakeries" "Desserts" "Cupcakes"
## $ :'data.frame': 2 obs. of 2 variables:
## ..$ alias: chr [1:2] "bbq" "foodtrucks"
## ..$ title: chr [1:2] "Barbeque" "Food Trucks"
## $ :'data.frame': 2 obs. of 2 variables:
## ..$ alias: chr [1:2] "grocery" "drugstores"
## ..$ title: chr [1:2] "Grocery" "Drugstores"
## $ :'data.frame': 3 obs. of 2 variables:
## ..$ alias: chr [1:3] "cosmetics" "drugstores" "convenience"
## ..$ title: chr [1:3] "Cosmetics & Beauty Supply" "Drugstores" "Convenience Stores"
## $ :'data.frame': 1 obs. of 2 variables:
## ..$ alias: chr "beer_and_wine"
## ..$ title: chr "Beer, Wine & Spirits"
## $ :'data.frame': 2 obs. of 2 variables:
## ..$ alias: chr [1:2] "cupcakes" "desserts"
## ..$ title: chr [1:2] "Cupcakes" "Desserts"
## $ :'data.frame': 3 obs. of 2 variables:
## ..$ alias: chr [1:3] "drugstores" "cosmetics" "convenience"
## ..$ title: chr [1:3] "Drugstores" "Cosmetics & Beauty Supply" "Convenience Stores"
## $ :'data.frame': 2 obs. of 2 variables:
## ..$ alias: chr [1:2] "grocery" "convenience"
## ..$ title: chr [1:2] "Grocery" "Convenience Stores"
## $ :'data.frame': 3 obs. of 2 variables:
## ..$ alias: chr [1:3] "italian" "desserts" "cocktailbars"
## ..$ title: chr [1:3] "Italian" "Desserts" "Cocktail Bars"
## $ :'data.frame': 2 obs. of 2 variables:
## ..$ alias: chr [1:2] "bakeries" "german"
## ..$ title: chr [1:2] "Bakeries" "German"
## $ :'data.frame': 3 obs. of 2 variables:
## ..$ alias: chr [1:3] "coffee" "coffeeroasteries" "beerbar"
## ..$ title: chr [1:3] "Coffee & Tea" "Coffee Roasteries" "Beer Bar"
## $ :'data.frame': 3 obs. of 2 variables:
## ..$ alias: chr [1:3] "coffee" "customcakes" "breakfast_brunch"
## ..$ title: chr [1:3] "Coffee & Tea" "Custom Cakes" "Breakfast & Brunch"
## [list output truncated]
glue::glue("there are {sum(is.na(yelp_flat$coordinates.latitude))} NA in the latitude column and {sum(is.na(yelp_flat$coordinates.longitude))} NA in the logitude column") %>%
print()
## there are 0 NA in the latitude column and 0 NA in the logitude column
yelp_concat %>%
map_dbl(., function(x) sum(is.na(x)))
## id alias name
## 0 0 0
## image_url is_closed url
## 0 0 0
## review_count categories rating
## 0 0 0
## transactions price phone
## 0 227 0
## display_phone distance coordinates.latitude
## 0 0 0
## coordinates.longitude location.address1 location.address2
## 0 20 143
## location.address3 location.city location.zip_code
## 200 0 0
## location.country location.state location.display_address
## 0 0 0
# get census boundary
tract <- suppressMessages(
get_acs(geography = "tract",
variables = c(hhincome = 'B19019_001',
race.tot = "B02001_001",
race.white = "B02001_002",
race.black = 'B02001_003'
),
state = "GA",
county = c("Fayette", "Spalding"),
year = 2019,
survey = "acs5",
geometry = TRUE,
output = "wide")
)
##
|
| | 0%
|
|= | 1%
|
|== | 2%
|
|== | 3%
|
|=== | 4%
|
|==== | 5%
|
|==== | 6%
|
|===== | 7%
|
|====== | 8%
|
|======= | 9%
|
|======= | 10%
|
|======= | 11%
|
|======== | 11%
|
|======== | 12%
|
|========= | 12%
|
|========= | 13%
|
|========== | 14%
|
|=========== | 15%
|
|============ | 17%
|
|============= | 18%
|
|============= | 19%
|
|============== | 20%
|
|============== | 21%
|
|=============== | 22%
|
|================ | 23%
|
|================= | 25%
|
|================== | 26%
|
|=================== | 27%
|
|==================== | 29%
|
|===================== | 30%
|
|====================== | 31%
|
|======================= | 33%
|
|======================== | 34%
|
|========================= | 35%
|
|========================= | 36%
|
|========================== | 37%
|
|=========================== | 38%
|
|=========================== | 39%
|
|============================ | 40%
|
|============================= | 41%
|
|============================= | 42%
|
|============================== | 42%
|
|=============================== | 44%
|
|=============================== | 45%
|
|================================ | 46%
|
|================================= | 48%
|
|================================== | 49%
|
|=================================== | 50%
|
|==================================== | 52%
|
|===================================== | 53%
|
|====================================== | 54%
|
|======================================= | 55%
|
|======================================= | 56%
|
|======================================== | 57%
|
|========================================= | 58%
|
|========================================== | 60%
|
|=========================================== | 61%
|
|=========================================== | 62%
|
|============================================ | 63%
|
|============================================= | 64%
|
|============================================== | 65%
|
|=============================================== | 67%
|
|================================================ | 68%
|
|================================================= | 69%
|
|================================================= | 71%
|
|================================================== | 72%
|
|=================================================== | 73%
|
|==================================================== | 75%
|
|===================================================== | 76%
|
|====================================================== | 77%
|
|======================================================= | 78%
|
|======================================================= | 79%
|
|======================================================== | 80%
|
|========================================================= | 81%
|
|========================================================= | 82%
|
|========================================================== | 82%
|
|========================================================== | 83%
|
|=========================================================== | 84%
|
|============================================================ | 86%
|
|============================================================= | 87%
|
|============================================================== | 88%
|
|=============================================================== | 90%
|
|=============================================================== | 91%
|
|================================================================ | 91%
|
|================================================================= | 92%
|
|================================================================== | 94%
|
|=================================================================== | 95%
|
|=================================================================== | 96%
|
|==================================================================== | 98%
|
|===================================================================== | 99%
|
|======================================================================| 100%
# Converting yelp_concat into a sf object
yelp_sf <- yelp_concat %>%
st_as_sf(coords=c("coordinates.longitude", "coordinates.latitude"), crs = 4326)
tract_sf <- tract%>%st_as_sf(crs=4326)
yelp_crs <- st_crs(yelp_sf)
tract_sf <- st_transform(tract_sf, crs = yelp_crs)
# sf subsets
yelp_in <- yelp_sf %>% st_intersection(tract_sf)
## Warning: attribute variables are assumed to be spatially constant throughout
## all geometries
glue::glue("nrow before: {nrow(ready4tidy)} -> nrow after: {nrow(yelp_in)} \n
ncol before: {ncol(ready4tidy)} -> ncol after: {ncol(yelp_in)} \n") %>%
print()
## nrow before: 1797 -> nrow after: 226
##
## ncol before: 16 -> ncol after: 33
tmap_mode("view")
## tmap mode set to interactive viewing
# most frequent rating is 4.5
rating_freq <- table(yelp_in$rating)
most_frequent_rating <- names(which.max(rating_freq))
hist(yelp_in$rating, main = "Rating Distribution", xlab = "Rating")
layer_rating<-tm_shape(yelp_in) + tm_dots(col = "rating")
layer_review<-tm_shape(yelp_in) + tm_dots(col = "review_count",palette='Purples')
layer_price<-tm_shape(yelp_in) + tm_dots(col = "price",palette='Greens')
layer_rating
layer_review
layer_price
The volumn of data shrinked largly after being tidied. Before tidying, there are {nrow(ready4tidy)} rows and {ncol(ready4tidy)} columns. After tidying, there are {nrow(yelp_in)} rows and {ncol(yelp_in)} columns.
The most frequent rating is 5. Yelp users tend to give high scores for food. Fayette County has more highly-rated food establishments than Spalding County. There are only a few food establishments with more than 200 reviews, and they are mostly located in the central area of the county. The prices of food vary, and their distribution appears random and is not significantly related to review counts and ratings..