This is an R Markdown Notebook.It illustrates how to create a map of Colombian cities using R.
We will use the leaflet library for mapping location.
The locations were downloaded from Bahar’s github website.
##install.packages("leaflet")
library (leaflet)
cities <- read.csv(file="ciudades.txt", header=FALSE, sep=";")
We visualize the “head” of the data that has been uploaded
head(cities)
class (cities)
## [1] "data.frame"
Then, we change the name of each category
names(cities)<- c("id","conuntry","city", "latitude", "longitude", "altitude")
We visualize the “tail” or the last 6 rows of the data
tail(cities)
We use the leaflet library that will able the map for us
leaflet(cities) %>%
addCircles(lng=~longitude,lat=~latitude)
Then, we add the default background, location markers and a pop-up message wich says the name of the city we are clicking
m <- leaflet(cities)%>%
addTiles()%>%
addMarkers (lng=~longitude, lat=~latitude, popup=~city)
m