Yelp Dataset Analysis

Loading Dataset

file <- "yelp_academic_dataset_business.json"
business <- jsonlite::stream_in(textConnection(readLines(file, n=300000)), flatten = TRUE)

Data samples:

A tabela abaixo mostra alguns exemplos de negócios registrados no dataset do Yelp. para visualização, estão mostradas apenas as 12 primeiras colunas e as 20 primeiras linhas do dataset.
head_business = head(business, 20)
datatable(head_business[,1:12], 
          options = list(
            pageLength = 5,
            scrollX = TRUE,
            autoWidth = TRUE
            ),
          class = 'cell-border stripe'
          )

Business by State:

Aqui é possível ver a porcentagem de negócios por estado. Cada cor representa um Estado americano contendo a porcentagem de negócios registrados no dataset.
state_counts <- business %>%
  group_by(state) %>%
  summarise(count = n())

fig <- plot_ly(data=state_counts, labels=~state_counts$state, values=~state_counts$count, type = 'pie')%>% 
  layout(title=list(text = "% Negócios por Estado Americano"), 
         legend=list(title=list(text='Estados')))
fig

Map visualization:

### this function will color each location based on the star rating it has
coffeeStores <- business # %>% filter(str_detect(str_to_lower(categories), str_to_lower("Coffee")))

colors <- colorFactor(c("purple", "red", "orange", "black","blue"),
                   domain = unique(coffeeStores$stars))
### this draws the map
map <- leaflet(coffeeStores, width = "100%") %>%
  addProviderTiles("CartoDB.Positron") %>%
  addCircleMarkers(
    color = ~colors(coffeeStores$stars),
    stroke = FALSE, fillOpacity = 0.5,
    lat = coffeeStores$latitude,
    lng = coffeeStores$longitude,
    clusterOptions = markerClusterOptions(),
    popup = as.character(head_business$name))
map