¿Qué es la Inteligencia Locacional (Location Intelligence)? Es la forma en la que se logran realizar una vizualización y analisis de datos geoespaciales, con el fin de tomar decisiones estrategicas en base a la ubicación. Todo gracias a la capacidad de identificar patrones, por su capacidad de recopilar, procesar y analizar la información geografica
A partir del video “Why is Location Intelligence Vital for Successful Business?” (https://www.youtube.com/watch?v=7YAlv93nQiY) y las respuestas a las instrucciones 1) – 10) ¿Cómo contribuye el proceso de análisis de Inteligencia Locacional a la Inteligencia de Negocios? Al brindar datos geograficos al analisis de los datos, permite tomar mejores decisiones estrategicas, como mejores estrategias de marketing, mejor seleccion de localización de un negocio, identificar donde se encuentra el mayor flujo de clientela en cierta localización, entre otras.
Brevemente describir con tus propias palabras qué es la herramienta Análisis de Sentimientos / Sentiment Analysis. ¿Porqué la herramienta Sentiment Analysis es relevante en el desarrollo de la Inteligencia de Negocios (Business Intelligence)? Procesa el lenguaje natural para identificar y clasificar las opiniones en texto como reseñas o opiniones, y clasificarlos como positivas, negativas o neutrales.
### LOADING REQUIRED LIBRARIES
# data analysis
library(dplyr) # grammar of data manipulation helping to resolve data manipulation difficulties
library(Hmisc) # useful functions for data analysis and high - level graphics
library(foreign) # read data stored by Minitab, SPSS, Stata
library(openxlsx) # open, read, write,and edit xlsx files
library(tidyverse) # collection of R packages designed for data science
# spatial data analysis
library(leaflet.extras) # to provide extra functionality to the leaflet R package
library(sp) # functions for plotting data as maps, spatial selection, methods for retrieving coordinates
library(sf) # encode spatial vector data
library(maps) # geographic maps
library(tmap) # generate thematic maps
library(spdep) # a collection of functions to create spatial weights matrices from polygon contiguities
library(terra) # methods for spatial data analysis
library(leaflet) # interactive maps
library(mapproj) # map projections
library(mapsapi) #
library(spatialreg) # spatial regression models
library(sfdep) # an interface to 'spdep' to integrate with 'sf' objects and the 'tidyverse
library(tidygeocoder) # makes getting data from geocoding services easy
library(mapboxapi) # 'Mapbox' Navigation APIs, including directions, isochrones, and route optimization.
# visualization
library(ggmap) # spatial data visualization
library(rgeoda) # spatial data analysis based on software GeoDa
library(ggplot2) # Grammar of graphics. System for declarative creating graphics
library(corrplot) # provides a visual exploratory tool on correlation matrix
library(RColorBrewer) # offers several color palettes
library(leafsync) # create small multiples of several leaflet web maps
library(htmltools) # tools for HTML generation and output
# others
library(rlang) # collection of frameworks and APIs for programming with R
library(classInt) # methods for choosing univariate class intervals for mapping or other graphic purposes
library(gridExtra) # to arrange and combine plots for easy comparison
library(knitr) # integrates computing and reporting
### Getting access to distance, reviews, and ratings by using Google Maps
library(tm) # a framework for text mining applications
library(wordcloud) # functionality to create pretty word clouds
library(wordcloud2) #
library(googleway) # provides a mechanism to access various Google Maps APIs, including plotting a Google Map from R and overlaying it with shapes and markers, and retrieving data from the places, directions, roads, distances, geocoding, elevation and timezone APIs
library(gmapsdistance) # allows to calculate distances for a database through Google maps
# library(hereR) # geocode and autocomplete addresses or reverse geocode POIs using the Geocoder API
library(osrm) # enables the computation of routes, trips, isochrones and travel distances matrices (travel time and kilometric distance).
### Text Mining
library(tm) # text mining functions
library(syuzhet) # includes four sentiment dictionaries and provides a method for accessing the robust, but computationally expensive, sentiment extraction tool developed in the NLP group at Stanford.
library(SnowballC)
library(wordcloud)
library(wordcloud2)
# library(remotes)
# library(openrouteservice)
# remotes::install_github("GIScience/openrouteservice-r")Mty <- leaflet() %>%
addTiles() %>%
setView(-100.31094, 25.66928, zoom = 15) %>% ### Mty downtown area
addMarkers(-100.31094, 25.66928, popup = "Monterrey Downtown Area")
Mty### Map coordinates of Parque Fundidora (Starting Point)
latitude <- 25.67885
longitude <- -100.28418
r <- 15000### Use the google_places function to make a call to the API and save the results
search_str <- google_places(search_string = 'restaurante chino', location=c(latitude,longitude), radius=r, key=gmaps_key)### The page_token is the way to tell Google to return the next 20 results in the search instead of only the first 20
search_str_add_one <- google_places(search_string = 'restaurante chino', location=c(latitude,longitude), radius=r, key=gmaps_key, page_token = search_str$next_page_token)### The page_token is the way to tell Google to return the next 20 results in the search instead of only the first 40
search_str_add_two <- google_places(search_string = 'restaurante chino', location=c(latitude,longitude), radius=r, key=gmaps_key, page_token = search_str_add_one$next_page_token)### The data frame will give you a wealth of information about each place, including its address, latitude & longitude coordinates, price level, star rating, number of ratings, categories, and more.
business_name <- c(search_str$results$name, search_str_add_one$results$name, search_str_add_two$results$name)
business_rating <- c(search_str$results$rating, search_str_add_one$results$rating, search_str_add_two$results$rating)
user_ratings_total <- c(search_str$results$user_ratings_total, search_str_add_one$results$user_ratings_total,search_str_add_two$results$user_ratings_total)
place_id <- c(search_str$results$place_id, search_str_add_one$results$place_id, search_str_add_two$results$place_id)
lat <- c(search_str$results$geometry$location$lat, search_str_add_one$results$geometry$location$lat, search_str_add_two$results$geometry$location$lat)
lon <- c(search_str$results$geometry$location$lng, search_str_add_one$results$geometry$location$lng, search_str_add_two$results$geometry$location$lng)
# write.csv(data, "D:\\CD2001C_AD2024\\Power_BI_Data_AD2024\\data_location_intl.csv", row.names=TRUE)data <- data.frame(business_name,business_rating,user_ratings_total,place_id,lat,lon)
# write.csv(data, "D:\\CD2001C_AD2024\\Power_BI_Data_AD2024\\data_location_intl.csv", row.names=TRUE)data_top_ratings <- data %>% slice_max(business_rating, n = 9)
data_low_ratings <- data %>% slice_min(business_rating, n = 9)### Lets visualize the reviews information by coffee shop
top_ratings_plot <- ggplot(data_top_ratings, aes(x=reorder(business_name,business_rating), y=business_rating)) +
geom_bar(stat="identity", fill="lightblue") +
labs(title="Restaurantes chinos - Top 10 Mejores Ratings", subtitle = "ZMM") +
coord_flip()
top_ratings_plotlow_ratings_plot <- ggplot(data_top_ratings, aes(x=reorder(business_name,user_ratings_total), y=user_ratings_total)) +
geom_bar(stat="identity", fill="lightblue") +
labs(title="Restaurante Chino - Top 10 más visitados", subtitle = "ZMM") +
coord_flip()
low_ratings_plottop_users_plot <- ggplot(data_low_ratings, aes(x=reorder(business_name,business_rating), y=business_rating)) +
geom_bar(stat="identity", fill="lightpink") +
labs(title="Restaurante Chino - Top 10 Peores Ratings", subtitle = "ZMM") +
coord_flip()
top_users_plotlow_users_plot <- ggplot(data_low_ratings, aes(x=reorder(business_name,user_ratings_total), y=user_ratings_total)) +
geom_bar(stat="identity", fill="lightpink")+
labs(title="Restaurante Chino - Top 10 Menos visitados", subtitle = "ZMM") +
coord_flip()
low_users_plot### Where in ZMM are located the hospitals characterized by the highest ratings?
register_google(key = gmaps_key)
ggmap(get_googlemap(center = c(lon = longitude, lat = latitude), zoom = 11)) +
stat_density2d(data = data_top_ratings, aes(lon, lat, fill = after_stat(level)),
geom = "polygon", alpha = 0.40) +
scale_fill_gradient(low = "green", high = "red", guide = "none") +
labs(x = '', y = '', title = "ZMM - Restaurantes Chinos con mejores ratings")### Where in ZMM are located the Hospitals characterized by the lowest ratings?
ggmap(get_googlemap(center = c(lon = longitude, lat = latitude), zoom = 11)) +
stat_density2d(data = data_low_ratings, aes(lon, lat, fill = after_stat(level)),
geom = "polygon", alpha = 0.42) +
scale_fill_gradient(low = "green", high = "red", guide = "none") +
labs(x = '', y = '', title = "ZMM - Restaurantes Chinos con peor ratings")## ℹ <https://maps.googleapis.com/maps/api/staticmap?center=25.67885,-100.28418&zoom=11&size=640x640&scale=2&maptype=terrain&key=xxx-TzTcERfzJ3o>
## request more details about the comida china using google_place_details()
reviews_top_ratings <- google_place_details(place_id = data_top_ratings$place_id[8], key = gmaps_key)
reviews_low_ratings <- google_place_details(place_id = data_low_ratings$place_id[8], key = gmaps_key)### Generate a vector containing only the text
top_ratings_text <- reviews_top_ratings$result$reviews$text
top_ratings_doc <- Corpus(VectorSource(top_ratings_text))
low_ratings_text <- reviews_low_ratings$result$reviews$text
low_ratings_doc <- Corpus(VectorSource(low_ratings_text))### Clean the text data
options(warn=-1)
top_ratings_doc <- top_ratings_doc %>% tm_map(removeNumbers) %>% tm_map(removePunctuation) %>% tm_map(stripWhitespace)
top_ratings_doc <- tm_map(top_ratings_doc, content_transformer(tolower))
top_ratings_doc <- tm_map(top_ratings_doc, removeWords, stopwords("english"))options(warn=-1)
low_ratings_doc <- low_ratings_doc %>% tm_map(removeNumbers) %>% tm_map(removePunctuation) %>% tm_map(stripWhitespace)
low_ratings_doc <- tm_map(low_ratings_doc, content_transformer(tolower))
low_ratings_doc <- tm_map(low_ratings_doc, removeWords, stopwords("english"))### Lets create a dataframe containing each word in the first column and their frequency in the second column.
options(warn=-1)
dtm_top <- TermDocumentMatrix(top_ratings_doc)
matrix_top <- as.matrix(dtm_top)
words_top <- sort(rowSums(matrix_top),decreasing=TRUE)
words_top_df <- data.frame(word = names(words_top),freq=words_top)
# write.csv(words_top_df, "D:\\CD2001C_AD2024\\Power_BI_Data_AD2024\\wordcloud_a.csv", row.names=TRUE)options(warn=-1)
dtm_low <- TermDocumentMatrix(low_ratings_doc)
matrix_low <- as.matrix(dtm_low)
words_low <- sort(rowSums(matrix_low),decreasing=TRUE)
words_low_df <- data.frame(word = names(words_low),freq=words_low)### We can now generate the word cloud according to the top and low ratings reviews.
set.seed(1234) # for reproducibility
### top ratings
# top_raiting_wc<-wordcloud(words = words_top_df$word, freq = words_top_df$freq, min.freq = 1, max.words=200, random.order=FALSE, rot.per=0.35, colors=brewer.pal(8, "Dark2"))
top_rating_wc <- wordcloud2(data = words_top_df, color = "random-dark", size = 0.6, shape = "circle")
top_rating_wc### low ratings
#low_raiting_wc<-wordcloud(words = words_low_df$word, freq = words_low_df$freq, min.freq = 1, max.words=200, random.order=FALSE, rot.per=0.35, colors=brewer.pal(8, "Dark2"))
low_rating_wc <- wordcloud2(data = words_low_df, color = "random-dark", size = 0.6, shape = "circle")
low_rating_wc## request more details about the restaurant using google_place_details()
C_China_reviews <- google_place_details(place_id = data$place_id[15], language = "es", key = "AIzaSyDMtkIEvUpFccyUCGxLgXO-TzTcERfzJ3o")
C_China_reviews## $html_attributions
## list()
##
## $result
## $result$address_components
## long_name short_name
## 1 550 550
## 2 Avenida Manuel L. Barragán Av. Manuel L. Barragán
## 3 Valle de Anáhuac Valle de Anáhuac
## 4 San Nicolás de los Garza San Nicolás de los Garza
## 5 Nuevo León N.L.
## 6 México MX
## 7 66457 66457
## types
## 1 street_number
## 2 route
## 3 sublocality_level_1, sublocality, political
## 4 locality, political
## 5 administrative_area_level_1, political
## 6 country, political
## 7 postal_code
##
## $result$adr_address
## [1] "Local 110 Plaza La Joya, <span class=\"street-address\">Av. Manuel L. Barragán 550</span>, <span class=\"extended-address\">Valle de Anáhuac</span>, <span class=\"postal-code\">66457</span> <span class=\"locality\">San Nicolás de los Garza</span>, <span class=\"region\">N.L.</span>, <span class=\"country-name\">México</span>"
##
## $result$business_status
## [1] "OPERATIONAL"
##
## $result$current_opening_hours
## $result$current_opening_hours$open_now
## [1] TRUE
##
## $result$current_opening_hours$periods
## close.date close.day close.time open.date open.day open.time
## 1 2025-03-16 0 2300 2025-03-16 0 1100
## 2 2025-03-17 1 2300 2025-03-17 1 1100
## 3 2025-03-18 2 2300 2025-03-18 2 1100
## 4 2025-03-12 3 2300 2025-03-12 3 1100
## 5 2025-03-13 4 2300 2025-03-13 4 1100
## 6 2025-03-15 6 0000 2025-03-14 5 1100
## 7 2025-03-16 0 0000 2025-03-15 6 1100
##
## $result$current_opening_hours$weekday_text
## [1] "lunes: 11:00–23:00" "martes: 11:00–23:00" "miércoles: 11:00–23:00"
## [4] "jueves: 11:00–23:00" "viernes: 11:00–24:00" "sábado: 11:00–24:00"
## [7] "domingo: 11:00–23:00"
##
##
## $result$delivery
## [1] TRUE
##
## $result$dine_in
## [1] TRUE
##
## $result$editorial_summary
## $result$editorial_summary$language
## [1] "es-419"
##
## $result$editorial_summary$overview
## [1] "Restaurante casual que ofrece un menú de fusión de varias cocinas asiáticas, como sushi y guisados al wok."
##
##
## $result$formatted_address
## [1] "Local 110 Plaza La Joya, Av. Manuel L. Barragán 550, Valle de Anáhuac, 66457 San Nicolás de los Garza, N.L., México"
##
## $result$formatted_phone_number
## [1] "81 3233 2215"
##
## $result$geometry
## $result$geometry$location
## $result$geometry$location$lat
## [1] 25.73768
##
## $result$geometry$location$lng
## [1] -100.3147
##
##
## $result$geometry$viewport
## $result$geometry$viewport$northeast
## $result$geometry$viewport$northeast$lat
## [1] 25.73907
##
## $result$geometry$viewport$northeast$lng
## [1] -100.3133
##
##
## $result$geometry$viewport$southwest
## $result$geometry$viewport$southwest$lat
## [1] 25.73637
##
## $result$geometry$viewport$southwest$lng
## [1] -100.316
##
##
##
##
## $result$icon
## [1] "https://maps.gstatic.com/mapfiles/place_api/icons/v1/png_71/restaurant-71.png"
##
## $result$icon_background_color
## [1] "#FF9E67"
##
## $result$icon_mask_base_uri
## [1] "https://maps.gstatic.com/mapfiles/place_api/icons/v2/restaurant_pinlet"
##
## $result$international_phone_number
## [1] "+52 81 3233 2215"
##
## $result$name
## [1] "Oriental Wok Anáhuac"
##
## $result$opening_hours
## $result$opening_hours$open_now
## [1] TRUE
##
## $result$opening_hours$periods
## close.day close.time open.day open.time
## 1 0 2300 0 1100
## 2 1 2300 1 1100
## 3 2 2300 2 1100
## 4 3 2300 3 1100
## 5 4 2300 4 1100
## 6 6 0000 5 1100
## 7 0 0000 6 1100
##
## $result$opening_hours$weekday_text
## [1] "lunes: 11:00–23:00" "martes: 11:00–23:00" "miércoles: 11:00–23:00"
## [4] "jueves: 11:00–23:00" "viernes: 11:00–24:00" "sábado: 11:00–24:00"
## [7] "domingo: 11:00–23:00"
##
##
## $result$photos
## height
## 1 4032
## 2 3024
## 3 3472
## 4 4032
## 5 4032
## 6 3024
## 7 1868
## 8 4608
## 9 2448
## 10 4624
## html_attributions
## 1 <a href="https://maps.google.com/maps/contrib/104595298535586425627">luis avelar</a>
## 2 <a href="https://maps.google.com/maps/contrib/109197942733752373678">Guadalupe Cantu</a>
## 3 <a href="https://maps.google.com/maps/contrib/115153180849401781964">Lupita Barrios Muñoz</a>
## 4 <a href="https://maps.google.com/maps/contrib/100128616113942673919">Dulce Rodarte</a>
## 5 <a href="https://maps.google.com/maps/contrib/111367996407708239408">Dalia Solís</a>
## 6 <a href="https://maps.google.com/maps/contrib/109974487658740371237">Leon RM</a>
## 7 <a href="https://maps.google.com/maps/contrib/116328250776931654857">Iván López García</a>
## 8 <a href="https://maps.google.com/maps/contrib/117641540256688034014">Suzett Jasso</a>
## 9 <a href="https://maps.google.com/maps/contrib/114244301252710537367">Dann Hernandez (JD5094)</a>
## 10 <a href="https://maps.google.com/maps/contrib/109983946338487252057">Angeles Barrón</a>
## photo_reference
## 1 AUy1YQ2eJTlJBff7FvPOWayfpgjY6VG3WoqVfVUPxgDjqW8ffQ3rmM77CNSTXl1Envxg7mq4pttkRwn0R_vaq3is5GgJXTXJW7lh0_AzuUWVw9cLUCLDWk-Hhoqps0gO1GU4xRxraljO54KVeqnKA2_Aw97oHoPzVmG3vZ5BHejWuHUjW-F-g26HDl12R_QWADGeadsg7Gl4Pe4XXGJjI2Os3r_dIvYKH5ZXqMekecVlY5J7hqTXIliPayF3Sm7mlkm3QlUkjzAKACZaqzJmcic6OxaKDcEDen6tu9IRaamsIao42p4H8ZTq0g5nbGN4CBIBoQEeN0TxL-4
## 2 AUy1YQ10YTwe8qLcH4kpM7jHo96dxzyjnwI0bGkJDKtGScxDTCw-f46RVh6DoSITfXNoWHI2rgYUt5WfZrx3C0EsrfkeOfurmND8H26ru_06umylGhK0bfwYqrIirMwkAZGe9rx8FT1xXC8CFAdoXYwZNLoZhstrMtbN0LAgnaFBnbP_36qK3R0pyzkzGRl6XKevHAcDKT41y3u1PlDr9tn8pBSpZLt7CfgqTjPctA9ZtQ37xmViu7ryBBVBD_5G5p8oVvNdsp02uXb8eZ_S87bH-VXPocPhcmOK-jtPXA1Z_VTSSDXy9fVL39N5NwR72K_ibhxT62JvkUQ
## 3 AUy1YQ25x8DqTgBitfgbrdjsowbacGRBu9q0ujP-o0VNivQStZ8Pqg52RjdCBS_fngH1g8lu6WcHYK5TiTb0Klxie1-MXuo8H8eVZauM-t_gJ0zlUX5nmQyZ8LIy0uFN-8--S7nssQaAZ6gAHtqO6BD6xIlm3hSpeKF_czQZHpg938PAHYIHsI5t11IR3hdo0yTcuLABT43D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UF3tsxfpMRiQ
## 10 AUy1YQ3SlpLNkIsqE0aSjUBIz0XxQaTpBBvQfaiv8Rsxak-KcoizNBykPNWg4DUgLJWtzUDH1P0KSoyIyVks9MuZW-xV5NANmhuTHh46fsVbbWTDOzSL06Okxk_OLMZrbIfaZV6c4vf2UHcUeDIVAdmWhKm45NJyMP3Z6ak38wFhqV9VXdCA-qhPM5bTauHRgFAjJu8PGv-UdTY1LYogAyAhMlAdvf41uCX1seRRsQvo7OLQq9LvOaExV_m0GXgOBSqIkQqlY1oKzwOomMwIEPEzeqRDVbGKxJUaDt2_tgzohd_kgwf1AM5pfMY2-tKjqcnBMj9_tmxgrsI
## width
## 1 3024
## 2 4032
## 3 4640
## 4 3024
## 5 3024
## 6 4032
## 7 4000
## 8 3456
## 9 3264
## 10 2608
##
## $result$place_id
## [1] "ChIJUSIW7l2UYoYRfmWsmC4oTfw"
##
## $result$plus_code
## $result$plus_code$compound_code
## [1] "PMQP+34 San Nicolás de los Garza, N.L., México"
##
## $result$plus_code$global_code
## [1] "75QXPMQP+34"
##
##
## $result$price_level
## [1] 2
##
## $result$rating
## [1] 4.3
##
## $result$reference
## [1] "ChIJUSIW7l2UYoYRfmWsmC4oTfw"
##
## $result$reservable
## [1] TRUE
##
## $result$reviews
## author_name
## 1 Martha M. Mendez A.
## 2 Debanny Martínez
## 3 bubulubii c:
## 4 Dulce Rodarte
## 5 Suzett Jasso
## author_url language
## 1 https://www.google.com/maps/contrib/104303907828966724052/reviews es
## 2 https://www.google.com/maps/contrib/115637926877780804974/reviews es
## 3 https://www.google.com/maps/contrib/116731230764560781696/reviews es
## 4 https://www.google.com/maps/contrib/100128616113942673919/reviews es
## 5 https://www.google.com/maps/contrib/117641540256688034014/reviews es
## original_language
## 1 es
## 2 es
## 3 es
## 4 es
## 5 es
## profile_photo_url
## 1 https://lh3.googleusercontent.com/a-/ALV-UjXYPbFOW9Ne-tAATYx_0qzQnt6VvtEusCF854utBdF3qQcIhHlJ2A=s128-c0x00000000-cc-rp-mo-ba5
## 2 https://lh3.googleusercontent.com/a-/ALV-UjXeigQDNpNvTKbCr56bH2DB_-ykPMkMDm90Hk8BV0dPKyZX0HUkWQ=s128-c0x00000000-cc-rp-mo
## 3 https://lh3.googleusercontent.com/a-/ALV-UjUsYUPDo5SjKQieqX7TclPCSouBDUnv11RGmA_prqN34E95CSN7sw=s128-c0x00000000-cc-rp-mo-ba3
## 4 https://lh3.googleusercontent.com/a-/ALV-UjUqU6173pZlytL-eUHgHqHRcQCBA7Z7QvlVtjW_XLjbhd83Ruo_=s128-c0x00000000-cc-rp-mo
## 5 https://lh3.googleusercontent.com/a-/ALV-UjVFjaT_brl8U7L9-R0tW4iyyp7r0OoolQvDXR4mc8vxfhKMJnZ7=s128-c0x00000000-cc-rp-mo-ba2
## rating relative_time_description
## 1 5 Hace 4 meses
## 2 5 Hace 1 mes
## 3 5 Hace 1 mes
## 4 5 Hace 2 semanas
## 5 5 Hace 9 meses
## text
## 1 La comida está bien , los rollos estaban ricos y la sopa si nos gustó. La bebida era gin de frutos rojos y estaba rica.\nLa comida le doy 9 de 10\nEl mesero fue amable, pero se tardaron mucho en traer la comida. Fácil unos 40min ,lo bueno que no tenía prisa.
## 2 Buen ambiente familiar, la comida deliciosa, la puedes pedir a tu gusto sin problema alguno, el servicio, muy amables todos.
## 3 Servicio muy bueno, meseros y gerente muy atentos. La comida estaba muy rica (:
## 4 Muy rico y nos atendieron muy rápido
## 5 Excelente lugar con un gran ambiente y una excelente atención \U{01faf6}🏻\nLa comida está deliciosa, pedí un ramen y un cosmo roll y un bonel roll todo super rico y no se diga las limonadas que venden \U{01faf6}🏻❤️\n100% recomendado
## time translated
## 1 1730762921 FALSE
## 2 1738452707 FALSE
## 3 1738452671 FALSE
## 4 1740176741 FALSE
## 5 1718073228 FALSE
##
## $result$serves_beer
## [1] TRUE
##
## $result$serves_breakfast
## [1] FALSE
##
## $result$serves_brunch
## [1] FALSE
##
## $result$serves_dinner
## [1] TRUE
##
## $result$serves_lunch
## [1] TRUE
##
## $result$serves_vegetarian_food
## [1] TRUE
##
## $result$takeout
## [1] TRUE
##
## $result$types
## [1] "restaurant" "food" "point_of_interest"
## [4] "establishment"
##
## $result$url
## [1] "https://maps.google.com/?cid=18180231451359602046"
##
## $result$user_ratings_total
## [1] 1512
##
## $result$utc_offset
## [1] -360
##
## $result$vicinity
## [1] "Local 110 Plaza La Joya, Avenida Manuel L. Barragán 550, Valle de Anáhuac, San Nicolás de los Garza"
##
## $result$website
## [1] "http://orientalwok.mx/"
##
## $result$wheelchair_accessible_entrance
## [1] TRUE
##
##
## $status
## [1] "OK"
### Based on google reviews lets generate a vector containing only the text.
### Corpus is a collection of written texts or a body of writing on a particular subject.
### Cleaning text data.
C_China_reviews_text <- C_China_reviews$result$reviews$text
C_China_reviews_doc <- Corpus(VectorSource(C_China_reviews_text)) ### Tokenization: Break down the text into individual words or tokens.
C_China_reviews_doc <- C_China_reviews_doc %>% tm_map(removeNumbers) %>% tm_map(removePunctuation) %>% tm_map(stripWhitespace)
C_China_reviews_doc <- tm_map(C_China_reviews_doc, content_transformer(tolower))
C_China_reviews_doc <- tm_map(C_China_reviews_doc, removeWords, stopwords("spanish"))dtm_C_China_reviews <- TermDocumentMatrix(C_China_reviews_doc)
matrix <- as.matrix(dtm_C_China_reviews)
words <- sort(rowSums(matrix),decreasing=TRUE)
words_df <- data.frame(word = names(words),freq=words)### Word cloud of 50 hospitals around the starting point (Parque Fundidora)
### words with frequency below min.freq will not be plotted
# wordcloud(words = words_df$word, freq = words_df$freq, min.freq = 5, max.words=200, random.order=FALSE, rot.per=0.35, colors=brewer.pal(8, "Dark2"))## 'data.frame': 53 obs. of 2 variables:
## $ word: chr "comida" "bueno" "rica" "ambiente" ...
## $ freq: num 6 2 2 2 2 2 2 2 2 1 ...
## word freq
## comida comida 6
## bueno bueno 2
## rica rica 2
## ambiente ambiente 2
## deliciosa deliciosa 2
## servicio servicio 2
### Word clouds are a visual representation of text data where words are arranged in a cluster. The size of each word reflects its frequency or importance in the data set.
wordcloud2(data = words_df, color = "random-dark", size = 0.5, shape = "circle")### term matrix is a table containing the frequency of the words.
tdm_sparse <- TermDocumentMatrix(C_China_reviews_doc, control = list(weighting = weightTfIdf))
tdm_m_sparse <- as.matrix(tdm_sparse)# lets display frequency of words
term_freq <- rowSums(tdm_m_sparse)
term_freq_sorted <- sort(term_freq, decreasing = TRUE)
tdm_d_sparse <- data.frame(word = names(term_freq_sorted), freq = term_freq_sorted)
# lets display the top 10 most frequent words
head(tdm_d_sparse, 10)## word freq
## atendieron atendieron 0.7739760
## rápido rápido 0.7739760
## rico rico 0.5007303
## atentos atentos 0.3317040
## gerente gerente 0.3317040
## meseros meseros 0.3317040
## servicio servicio 0.2990075
## bueno bueno 0.2489345
## rica rica 0.2489345
## excelente excelente 0.2110844
# lets convert review column of dataframe to character vector so we can generate sentiment scores
text <- iconv(C_China_reviews_text)# Syuzhet method: It is an algorithm used to extract emotions from a sentence. It is a sentiment lexicon that can be used with non-English texts.
syuzhet_vector <- get_sentiment(text, method = "syuzhet") ### get_sentiment() function is used to analyze sentiment.
# See first row of vector
head(syuzhet_vector)## [1] 0.00 1.05 0.00 0.00 0.50
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.00 0.00 0.00 0.31 0.50 1.05
# Using the full dataset for sentiment analysis might still
text_sampled <- iconv(C_China_reviews_text)
syuzhet_vector_sampled <- get_sentiment(text_sampled, method = "syuzhet")ggplot(data.frame(syuzhet_vector_sampled), aes(x = syuzhet_vector_sampled)) +
geom_histogram(binwidth = 0.1, fill = "blue", color = "black") +
labs(title = "Sentiment Distribution using Syuzhet Method (Sampled Data)", x = "Sentiment Score", y = "Frequency") +
theme_minimal()nrc_sampled <- get_nrc_sentiment(text_sampled) ### sentiment dictionary to calculate the presence of eight different emotions and their corresponding valence in a text file
nrct_sampled <- data.frame(t(nrc_sampled))
nrcs_sampled <- data.frame(rowSums(nrct_sampled))
nrcs_sampled <- cbind("sentiment" = rownames(nrcs_sampled), nrcs_sampled)
rownames(nrcs_sampled) <- NULL
names(nrcs_sampled)[1] <- "sentiment"
names(nrcs_sampled)[2] <- "frequency"
nrcs_sampled <- nrcs_sampled %>% mutate(percent = frequency/sum(frequency))
nrcs2_sampled <- nrcs_sampled[1:8, ]
colnames(nrcs2_sampled)[1] <- "emotion"### 1) The bar plot illustrating the distribution of emotions based on sentiment analysis using the NRC lexicon on the google reviews
### 2) Each bar represents a different emotion, and the height of the bar indicates the frequency of that emotion within the text data.
ggplot(nrcs2_sampled, aes(x = reorder(emotion, -frequency), y = frequency, fill = emotion)) +
geom_bar(stat = "identity") +
labs(title = "Emotion Distribution (Sampled Data)", x = "Emotion", y = "Frequency") +
theme_minimal() +
scale_fill_brewer(palette = "Set3")### 1) The output is a horizontal bar plot illustrating the frequency of the top 10 most popular words in the text data.
### 2) Each bar represents a word, and the length of the bar indicates the frequency of that word in the dataset.
tdm_d_sparse <- tdm_d_sparse[1:10, ]
tdm_d_sparse$word <- reorder(tdm_d_sparse$word, tdm_d_sparse$freq)
ggplot(tdm_d_sparse, aes(x = word, y = freq, fill = word)) +
geom_bar(stat = "identity") +
coord_flip() +
labs(title = "Most Popular Words", x = "Word", y = "Frequency") +
theme_minimal()# lets create a data frame with sentiment and count
sentiment_df <- data.frame(sentiment = c("Positive", "Negative", "Neutral"), count = c(sum(syuzhet_vector_sampled > 0), sum(syuzhet_vector_sampled < 0), sum(syuzhet_vector_sampled == 0)))# Create a pie chart
### 1) The output is a pie chart illustrating the distribution of sentiment categories within the dataset.
### 2) Each segment of the pie chart represents a sentiment category (“Positive”, “Negative”, “Neutral”), and the size of each segment corresponds to the count of that sentiment category in the dataset.
ggplot(sentiment_df, aes(x = "", y = count, fill = sentiment)) +
geom_bar(stat = "identity", width = 1) +
coord_polar("y", start = 0) +
labs(title = "Sentiment Distribution", x = "", y = "") +
theme_minimal() +
scale_fill_brewer(palette = "Set3")Brevemente describir los 4 - 6 principales hallazgos identificados en el proceso de análisis de Google Maps Reviews y análisis de sentimientos (sentiment analysis). - El peor de todos los restaurantes es Fe Ling, la cual no tiene tantos visitantes, pero se podria considerar que el peor de - todos tomando en cuenta cantidad de reviews y ratings, seria Chino Jr. - Donde se encuentrar la concentración de los peores restaurantes chinos es en la zona de Valle Verde. - El mejor restaurante considerando cantidad de visitas y rating, sería Jia Fu Comida. - Los mejores restuaruantes se encuentrar en Zona Mitras y centro.
¿Cuáles son las unidades de negocio con los niveles de raiting más alto? ¿Cuál es la ubicación de las unidades de negocio con los mejores raitings? ¿Cuáles son las principales características locacionales, “reviews”, y de tipo de percepción por parte de los clientes? Yalin Chen, Jia Fu, Xiang Long, Ninety Nine, Ming Xing, La Gran muralla, Hui Xin, Chinese City, China House y China King Se encuentran en Zona Mitras y centro. Te tratan bien, esta limpio, el sabor de la comida como el pollo, y de muy buen precio.
¿Cuáles son las unidades de negocio con los niveles de raiting más bajo? ¿Cuál es la ubicación de las unidades de negocio con los menores raitings? ¿Cuáles son las principales características locacionale y “reviews” por parte de los clientes? Wang Wang, Chef Oriental, Fe Ling, Huixin, El Chino Jr, son restaurantes peor valorados, ubicados por la zona de Valle Verde. En estos lugares la queja más común es que las porciones de los platos no son tan bastas, para el costo. ¿Qué tipo de sentimiento describen los comentarios de Google Reviews de las unidades de negocio seleccionadas? Según el analisis de sentimientos, disgusto, miedo, enojo y tristeza son los sentimientos más presentes, debe ser por las criticas a los negocios.