Leaflet is the R package that provides a convenient way to present data related to maps.
Below is the simple example where the most populated cities on the globe are presented in the animated way.
I have selected the cities with population > 10M and marked them on the map with different colors.
The popups give information on city, country and population.
library(leaflet)
## reading info on cities from https://simplemaps.com/data/world-cities
world.cities <- read.csv("worldcities.csv")
world.cities <- na.omit(world.cities)
## selecting cities with population >10M
top_cities <- world.cities[as.numeric(world.cities$pop) > 10000000,]
## adding colors factors
col <- c("blue", "green","yellow","red")
labs <- c("10-15M","15-25M","25-35M","35M+")
top_cities$group <- as.factor(col[round(top_cities$pop/10000000)])
## plotting map
top_cities %>%
leaflet() %>%
addTiles() %>%
addCircles(weight = 1, radius = sqrt(top_cities$pop) * 30,lat=top_cities$lat,
lng=top_cities$lng, popup=paste(top_cities$City,
top_cities$Country,top_cities$pop), fillColor = top_cities$group,
fillOpacity=0.5) %>%
addLegend(position="topright", colors=col, labels=labs)
Cities with population above 10M people