forked from musa-6110-fall-2023/story-map-project
-
Notifications
You must be signed in to change notification settings - Fork 39
Anna Duan - Philadelphia ethnic food clusters #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
annaduan09
wants to merge
13
commits into
Weitzman-MUSA-JavaScript:main
Choose a base branch
from
annaduan09:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
d907fa1
exploratory viz. saving before changing to api call via lon/lat
annaduan09 a3c3897
switch to neighborhood coords + smaller search radius
annaduan09 38fc77f
error handling for yelp api call
annaduan09 11f86c9
exploratory viz
annaduan09 984350b
pizza isn't always italian
annaduan09 9521f86
recategorizing and prioritizing cuisines
annaduan09 a190a11
finished grouping cuisines, creating slide jsons
annaduan09 73e1c0d
cuisine slides added
annaduan09 438aead
initial slides done, working on color mapping and styles
annaduan09 6018f7b
added an empty line
annaduan09 aedde4c
new mapping + leaflet legend + starting to flesh out slides
annaduan09 20b1348
Texted added, legends fixed
annaduan09 1aa3872
Additional linting fixes from lecture recording
annaduan09 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| node_modules/ | ||
| .Rproj.user |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "recommendations": [ | ||
| "dbaeumer.vscode-eslint" | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| --- | ||
| title: "analysis and viz" | ||
| author: "Anna Duan" | ||
| date: "`r Sys.Date()`" | ||
| output: html_document | ||
| --- | ||
|
|
||
| ```{r setup, include=FALSE} | ||
| knitr::opts_chunk$set(echo = TRUE) | ||
|
|
||
| library(tidyverse) | ||
| library(sf) | ||
| library(wordcloud2) | ||
| library(tm) | ||
| library(tigris) | ||
|
|
||
|
|
||
| neighs <- st_read("working data/phl_neighs.geojson") %>% | ||
| st_transform(4326) %>% | ||
| select(MAPNAME, Shape_Area) | ||
|
|
||
| restaurants <- st_read("data/restaurants_final.geojson") | ||
| top_cuisine_tract <- st_read("data/top_cuisine_tract.geojson") | ||
| top_cuisine_neigh <- st_read("data/top_cuisine_neigh.geojson") | ||
|
|
||
|
|
||
| cuisine_colors <- c("Caribbean" = "cyan", "Chinese" = "goldenrod2", "East_European" = "dodgerblue3", "Japanese" = "darkcyan", "Korean" = "orchid1", "Latin_American" = "pink2", "Mediterranean" = "olivedrab2", "Mexican" = "gold1", "Middle_Eastern" = "salmon1", "Soul_Food" = "lightblue1", "South_Asian" = "olivedrab4", "Thai" = "tan", "United_Kingdom" = "orchid3", "Vietnamese" = "salmon3", "West_African" = "darkslategray") | ||
| ``` | ||
|
|
||
| # Wordclouds | ||
| ```{r wordclouds} | ||
| # Yelp description | ||
| text <- restaurants$title | ||
| docs <- Corpus(VectorSource(text)) %>% | ||
| tm_map(removeNumbers) %>% | ||
| tm_map(removePunctuation) %>% | ||
| tm_map(stripWhitespace) %>% | ||
| tm_map(., content_transformer(tolower)) %>% | ||
| tm_map(., removeWords, stopwords("english")) | ||
| dtm <- TermDocumentMatrix(docs) | ||
| matrix <- as.matrix(dtm) | ||
| words <- sort(rowSums(matrix),decreasing=TRUE) | ||
| df <- data.frame(word = names(words),freq=words) %>% | ||
| filter(!word %in% c('food', 'fast', 'restaurants', 'delivery', 'services', | ||
| 'trucks', 'grocery', 'shops', 'stores', 'sports', 'bars', | ||
| 'breakfast', 'brunch', 'new','convenience', 'stands', 'american')) | ||
|
|
||
| wordcloud2(data = df, size = 3, color = "random-light") | ||
|
|
||
| # Cuisine | ||
| text <- restaurants$cuisine | ||
| docs <- Corpus(VectorSource(text)) %>% | ||
| tm_map(removeNumbers) %>% | ||
| tm_map(removePunctuation) %>% | ||
| tm_map(stripWhitespace) %>% | ||
| tm_map(., content_transformer(tolower)) %>% | ||
| tm_map(., removeWords, stopwords("english")) | ||
| dtm <- TermDocumentMatrix(docs) | ||
| matrix <- as.matrix(dtm) | ||
| words <- sort(rowSums(matrix),decreasing=TRUE) | ||
|
|
||
| df <- data.frame(word = names(words),freq=words) | ||
|
|
||
| wordcloud2(data = df, size = 3, color = "random-light") | ||
| ``` | ||
| # Cuisine dist | ||
| ```{r cuisine distribution} | ||
|
|
||
| # Location of all restaurants | ||
| ggplot() + | ||
| # geom_sf(data = st_union(neighs), fill = "gray90", color = "transparent") + | ||
| geom_sf(data = restaurants, color = "darkcyan", size = 0.5, alpha = 0.2) + | ||
| labs( | ||
| title = "Philadelphia Ethnic Restaurants", | ||
| subtitle = "n = 2,288" | ||
| ) + | ||
| theme_void() | ||
|
|
||
|
|
||
| ggplot() + | ||
| geom_bar(data = restaurants, aes(x = cuisine_group), show.legend = FALSE, fill = "darkcyan") + | ||
| coord_flip() + | ||
| scale_x_discrete(limits = restaurants%>% count(cuisine_group) %>% arrange(n) %>% pull(cuisine_group)) + | ||
| labs( | ||
| x = "Cuisine group", | ||
| y = "Number of restaurants" | ||
| ) + | ||
| theme_minimal() + | ||
| theme(text = element_text(color = "gray20")) | ||
| ``` | ||
|
|
||
| ```{r map all restaurants} | ||
| # Map most common cuisine in each neighborhood | ||
| ggplot() + | ||
| geom_sf(data = st_union(neighs), fill = "gray95", color = "transparent") + | ||
| geom_sf(data = top_cuisine_neigh %>% filter(count > 2), aes(fill = cuisine), color = "white") + | ||
| scale_fill_manual(values = cuisine_colors) + | ||
| labs( | ||
| title = "Most Common Cuisine in Each Neighborhood", | ||
| fill = "Cuisine" | ||
| ) + | ||
| theme_void() | ||
|
|
||
| # Map most common cuisine in each census tract | ||
| ggplot() + | ||
| geom_sf(data = top_cuisine_tract %>% filter(count > 2), aes(fill = cuisine), color = "white") + | ||
| scale_fill_manual(values = cuisine_colors) + | ||
| labs( | ||
| title = "Most Common Cuisine in Each Tract", | ||
| fill = "Cuisine" | ||
| ) + | ||
| theme_void() | ||
|
|
||
| ``` | ||
|
|
||
| ```{r spruce hill} | ||
| ggplot() + | ||
| geom_sf(data = spruce_hill_restaurants, aes(color = mid_east)) + | ||
| labs( | ||
| title = "Restaurants in Spruce Hill", | ||
| fill = "Cuisine" | ||
| ) + | ||
| theme_void() | ||
|
|
||
| ``` |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: I might recommend some background on your legend to make the text a little more readable on top of the map tiles.