In Colombia, the Ministry of Information Technologies, is driving a project to install free wifi points at strategic places all over the main cities, to provide the citizens, a tools to be more connected to the information technologies, over the city of Medellin, the Ministry has installed over 104 free wifi points, but only 54 of the has the location available in the public dataset. The information is available in the data goverment of colombia page
First, we are going to load the leaflet and dplyr libraries
suppressPackageStartupMessages(library(dplyr))
suppressPackageStartupMessages(library(leaflet))
if(dir.exists("./data")){
dir.create("./data")
}
url <- "https://www.datos.gov.co/api/views/kkkb-uzjh/rows.csv?accessType=DOWNLOAD"
destfile <- "./data/Wifi_medellin.csv"
download.file(url, destfile)
head(wifi, 3)
COMUNA Nombre.Comuna Barrio
1 1 POPULAR POPULAR
2 1 POPULAR VILLA GUADALUPE
3 1 POPULAR SANTO DOMINGO SAVIO NO. 2
Nombre.del.sitio
1 Metro de MedellÃn - Plazoleta estación de metrocable popular 1
2 Parque de Guadalupe
3 Plazoleta ubicada entre la IE Antonio Derka y la IE Santo Domingo Savio
Dirección Punto
1 Calle 107b Carrera 42b (6.295134, -75.548190000000005)
2 Carrera 42B # 95A-23 (6.2870790000000003, -75.549459999999996)
3 Carrera 28 # 107-205 (6.2976599999999996, -75.538072999999997)
The latitude and the longitude are in the same column and as a character, let’s separate them so we can use the in a leaflet object.
colnames(wifi) <- c("Comuna", "Nombre_comuna", "Barrio", "Nombre_sitio", "Direccion", "Punto") # Changing the names of the columns
lat_lng <-strsplit(substr(wifi$Punto,2, nchar(wifi$Punto)-1), ", ", "") # Splitting the data
get_lat <- function(x){x[1]} # Creating a function to get the latitude
get_lng <- function(x){x[2]} # Creating a function to get the longitude
wifi$lat <- as.numeric(sapply(lat_lng, get_lat)) #Changing the data type
wifi$lng <- as.numeric(sapply(lat_lng, get_lng)) #Changing the data type
NANs <-!is.na(wifi$lat) # Getting the NANs
wifi_v2 <- wifi[NANs,] # Setting the new dataset
# The last latitude data does not have the first digit.
index <- which(wifi_v2[,"lat"] < 6)
wifi_v2[index, "lat"] <- wifi_v2[index,"lat"]+6
Wifi_icon <- makeIcon(iconUrl = "./data/wi-fi-connection-issues.png",
iconWidth = 15, iconHeight = 15,
iconAnchorX = 16, iconAnchorY = 16)
Medellin_wifi <- leaflet() %>%
addTiles(attribution = "Public wifi points over Medellin city") %>%
addMarkers(lat = wifi_v2$lat,
lng = wifi_v2$lng,
icon = Wifi_icon,
popup = paste("Comuna:", wifi_v2$Nombre_comuna,
"<br> Barrio:",wifi$Barrio))
Medellin_wifi