apiKey <- "AIzaSyBPxhDW9_bUJ1juxXEGvY_QcNIZNJPUy7A"
#apiKey <- "AIzaSyDTuCBAZssit5sn2joqEeL6cghRXJ99pHA"
library(ggplot2)
library(ggmap)
## Warning: package 'ggmap' was built under R version 4.0.5
## Google's Terms of Service: https://cloud.google.com/maps-platform/terms/.
## Please cite ggmap if you use it! See citation("ggmap") for details.
register_google(apiKey)
qmap(c(-76.5, 3.43), zoom=12, maptype ='hybrid')
## Source : https://maps.googleapis.com/maps/api/staticmap?center=3.43,-76.5&zoom=12&size=640x640&scale=2&maptype=hybrid&language=en-EN&key=xxx

paradasMio <- read.delim("~/Inteligencia de negocios/Mapas/MIO_STOPS.txt")
# Adicionar columna de agrupamiento
k = 7
nIter = 100
grupos <- kmeans(paradasMio[,c(7,8)], k, iter.max = nIter, nstart = 1)
paradasMio$grupos <- grupos$cluster
# Polígono
cluster <- subset(paradasMio, paradasMio$grupos==1)
indicesC1 <- chull(cluster[,c(7,8)])
poligono <- paradasMio[indicesC1,]
#mapa <- ggplot(paradasMio, aes(DECIMALLONGITUDE, DECIMALLATITUDE))
city <- get_map(c(-76.5, 3.43), zoom=12)
## Source : https://maps.googleapis.com/maps/api/staticmap?center=3.43,-76.5&zoom=12&size=640x640&scale=2&maptype=terrain&language=en-EN&key=xxx
mapa <- ggmap(city)
mapa <- mapa + geom_point(data=paradasMio, aes(x=DECIMALLONGITUDE, y=DECIMALLATITUDE,
color= grupos),
size=paradasMio$PASSANGERS_NUM*0.02)
mapa <- mapa + geom_polygon(data=poligono, aes(x=DECIMALLONGITUDE, y=DECIMALLATITUDE),
color='black', alpha=0.2)
mapa
