globeMap <- read.csv("C:/Users/i5 decima G/OneDrive/Escritorio/Proyecto R/globeMap.csv")
# Llave de acceso
apikey <- "AIzaSyBPxhDW9_bUJ1juxXEGvY_QcNIZNJPUy7A"
library(ggplot2)
library(ggmap)
## 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("C:/Users/i5 decima G/OneDrive/Escritorio/Proyecto R/MIO_STOPS.txt")
# Asignación una 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,]
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=paradasmio$grupos,size=paradasmio$PASSANGERS_NUM*0.02)
mapa <- mapa + geom_polygon(data = poligono,aes(x=DECIMALLONGITUDE,y=DECIMALLATITUDE),color="black",alpha=0.02)
mapa

R Maps