To install packages, enable KPI, and prepare data
install.packages('googleway')
install.packages("writexl")
install.packages('geosphere')
library(googleway)
library(writexl)
library(dplyr)
library(geosphere)
## Enabling API on Google Cloud
myApi = 'AIzaSyCzMc0FVwsEbSGEsBvTzQKY59UsnEN9fNE'
## Finding All of Chun Shui Tang Branches
search_str <- google_places(search_string = 'Chun Shui Tang in Taiwan',
location=c(23.899504, 120.981795),
radius=50000, key=myKpi)
round2 <- google_places(search_string = 'Chun Shui Tang in Taiwan',
location=c(23.899504, 120.981795),
radius=50000, key=myKpi,
page_token = search_str$next_page_token)
round3 <- google_places(search_string = 'Chun Shui Tang in Taiwan',
location=c(23.899504, 120.981795),
radius=50000, key=myKpi,
page_token = round2$next_page_token)
## Keeping Results
result <- search_str$results
result2 <-round2$results
result3 <-round3$results
## Clustering Part
#Mean of Lat Lon
MeanLat <- mean(final_df$lat, na.rm = TRUE)
MeanLon <- mean(final_df$lng, na.rm = TRUE)
#Hierarchical Clustering
hc <- hclust(DMat, method="complete")
final_df$Clusters <- cutree(hc, k = 8)
Convert data to the appropriate data frame
## Binding Back Latitude and Longitude Data
result <- search_str$results %>%
cbind(., search_str$results$geometry$location)
result2 <- round2$results %>%
cbind(., round2$results$geometry$location)
result3 <- round3$results %>%
cbind(., round3$results$geometry$location)
## Convert to Dataframe
df <- as.data.frame(result)
df2 <- as.data.frame(result2)
df3 <- as.data.frame(result3)
Export to Excel file
# Specify the corrected file path with double backslashes or forward slashes
file_path <- "C:/Users/Phetcharee/Desktop/CSTProject/chun_shui_tang_branches.xlsx"
# Write final_df to Excel file
write_xlsx(final_df, path = file_path)
To generate the distance matrix table
#Distance of all stores from mean lat lon
CSTLatLon <- final_df[,c(17,18)]
#Distance Matrix
Distance_Mat<- distm(CSTLatLon[2:1],CSTLatLon[2:1],
fun = distHaversine)
Distance_Mat<- as.data.frame(Distance_Mat)
Distance_Mat[is.na(Distance_Mat)]<-0
DMat<- as.dist(Distance_Mat)
# Bind data frames together using dplyr's bind_rows function
final_df <- bind_rows(df, df2, df3)
Based on my observation of the location points on the map, Chun Shui Tang has three main areas where its stores are located. The first area is Taichung, which has ten stores with an average customer rating of 4.06. Additionally, the Chun Shui Tang Siwei original store has the most reviews on Google Maps.
The brand has eight stores in the Taipei area, with an average rating score of 3.90. After reviewing customer complaints, it appears that the main issues are the waiting times at each branch and the quality of the services provided, which the brand needs to improve.
In the Taoyuan area, Chun Shui Tang has only two operating stores with an average rating score of 3.95. However, these two stores have the lowest user rating numbers, getting only 3.34% of all customers who review on Google Maps.