Read in Packages and Yelp Data

To read in the yelp data, I copy and pasted my mini RMD into an R Script in the project directory. This script is called “Yelp Pull.R”…

Tidy Data

By doing each of the following: - Delete duplicated rows - Flatten nested columns - Delete rows with missing coordinates

white_camping_clean <- white_camping_yelp %>%
  
  #Delete duplicate rows on the basis of the yelp id
  filter(!duplicated(`id`)) %>%
  
  #Delete rows with missing coordinates
  filter(!is.na(geometry)) %>%
  
  #Delete observations that are outside the tracts of interest.
  filter(geometry %in% st_intersection(white_camping_yelp$geometry, st_transform(whiteCountyTracts$geometry, crs = epsg_id)))

tmap_mode('view')
## tmap mode set to interactive viewing
#Plot the old map
tm_shape(whiteCountyTracts) + tm_polygons(id = c('Tract Name' = 'NAMELSAD')) +
  tm_shape(white_camping_yelp) + tm_dots(col = c('Business Category' = 'coffee_or_camp'), jitter = .5, title = 'Business Category, Untidied Data', id = 'name')
#Plot the new map
tm_shape(whiteCountyTracts) + tm_polygons(id = c('Tract Name' = 'NAMELSAD')) +
  tm_shape(white_camping_clean) + tm_dots(col = c('Business Category' = 'coffee_or_camp'), jitter = .5, title = 'Business Category, Tidied Data', id = 'name')

I already unnested and flattened the dataframe in Mini 1, here is the code I used to do that

#Convert x, y coords to ST points, normalized with a crs
  frameGeom <- frame %>%
    #Rename the alias field to unnest the categories
    rename('alias.business' = alias) %>%
    #Unnest and pivot into one categories column
    unnest_wider(categories, transform = ~ paste(.x, collapse = ', ')) %>%
    
    #Rename the category variables
    rename('title.category' = 'title',
           'alias.category' = 'alias'
    ) %>%
    
    #Flatten nested frame
    jsonlite::flatten() %>%
    st_as_sf(coords = c('coordinates.longitude', 'coordinates.latitude'), crs = epsg_id)
  return(frameGeom)

Exploratory Data Analysis

Plot the distribution of review scores for all categories, then split up by categories

ggplot(white_camping_clean, aes(x = coffee_or_camp, y = rating)) +
  geom_violin(aes(fill = coffee_or_camp)) +
  geom_boxplot(width = 0.1, fill = 'light grey', alpha = 0.5) +
  theme(legend.position = 'None') +
  labs(x = '', y = 'Rating', title = 'Rating Distribution of Each Category')

Now let’s plot a map of the highest rated coffee shops and campground (rating of 5). Then we’ll plot a map of the best coffee shop and best campground (highest rating * number of reviews)

#Plot the map where rating == 5
tm_shape(whiteCountyTracts) + tm_polygons(id = c('Tract Name' = 'NAMELSAD')) +
  tm_shape(white_camping_clean %>% filter(rating == 5)) + tm_dots(col = c('Business Category' = 'coffee_or_camp'), jitter = .5, title = 'Business Category, Rating = 5', id = 'name')
#Plot the best
tm_shape(whiteCountyTracts) + tm_polygons(id = c('Tract Name' = 'NAMELSAD')) +
  tm_shape(white_camping_clean %>% group_by(coffee_or_camp) %>% filter(rating * review_count == max(rating * review_count))) + 
  tm_dots(col = c('Business Category' = 'coffee_or_camp'), jitter = .5, title = 'Business Category, Best Overall', id = 'name')

A Short Story About my Findings

After tidying and deduping the data, I found that there were only 19 unique coffee shops / campgrounds in White County (vs 67 total businesses originally). To me, this makes sense because White County is a very rural area in the state. Through this analysis, I was particularly interested in seeing the differences in ratings between coffee shops and campgrounds in the county, alongside which coffee shops and campgrounds were rated highest. As it turns out, campgrounds were generally more higher rated than the coffee shops. This makes sense, because the natural vistas in White County far exceed those of other parts of the country, whereas I wouldn’t necessarily contend that the best coffee in White County stacks up to the best coffee in Atlanta. Nonetheless, it turns out the best campground in White County (Nacoochee Adventures) is in the same census tract as the best coffee shop in the county (Sweetwater Coffeehouse). With this information in mind, perhaps I could make a quick trip to this campsite, and grab the best cup of joe in town right down the road!