Mapa
library(ggplot2)
library(ggmap)
register_google(apiKey)
qmap(c(-76.5, 3.43), zoom=12 )

Cargando los Datos de las paradas del MIO
MIO_STOPS <- read.delim("D:/Maestria/Primer Semestre/Visualizacion/Mapa/MIO_STOPS.txt")
city = get_map(c(-76.5, 3.43), zoom=12 )
mapa = ggmap(city)
mapa = mapa + geom_point( data = MIO_STOPS , aes(x= DECIMALLONGITUDE , y=DECIMALLATITUDE),color=MIO_STOPS$TYPE_BUS , size=MIO_STOPS$PASSANGERS_NUM*0.05)
mapa

Realizar un clustering
# Realizar un agrupamiento por kmeans
datos = MIO_STOPS[,c(7,8)]
grupos = kmeans(datos, centers = 3, iter.max = 100 , nstar = 1)
## Adicional una columna de agrupamiento
MIO_STOPS$grupos = grupos$cluster
#Poligono
cluster = subset(MIO_STOPS, MIO_STOPS$grupos==1)
indicesC1 = chull( cluster[,c(7,8)] )
poligono = MIO_STOPS[indicesC1,]
# cargando el mapa
city = get_map(c(-76.5, 3.43), zoom=12 )
mapa = ggmap(city)
mapa = mapa + geom_point( data = MIO_STOPS , aes(x= DECIMALLONGITUDE , y=DECIMALLATITUDE),color=MIO_STOPS$grupos, size=MIO_STOPS$PASSANGERS_NUM*0.05 )
mapa = mapa + geom_polygon(data=poligono, aes(x= DECIMALLONGITUDE , y=DECIMALLATITUDE))
mapa
