This is a simple example of a map using the leaflet
package in R. The map shows the top 20 countries by population in 2024.
The size of the circle represents the population of each country.
library(leaflet)
library(dplyr)
library(tidyr)
# Top 20 countries by population(2024)
population_data <- data.frame(
country = c("India", "China", "United States", "Indonesia", "Pakistan", "Nigeria", "Brazil", "Bangladesh", "Russia", "Ethiopia",
"Mexico", "Japan", "Philippines", "Egypt", "DR Congo", "Vietnam", "Iran", "Turkey", "Germany", "Thailand"),
population = c(1441700000, 1425200000, 341800000, 279800000, 245200000, 229200000, 217600000, 174700000, 144000000, 129700000,
129400000, 122600000, 119100000, 114500000, 105600000, 99500000, 89800000, 86300000, 83300000, 71900000),
lat = c(20.5937, 35.8617, 37.0902, -0.7893, 30.3753, 9.0820, -14.2350, 23.6850, 61.5240, 9.145,
23.6345, 36.2048, 12.8797, 26.8206, -4.0383, 14.0583, 32.4279, 38.9637, 51.1657, 15.8700),
lng = c(78.9629, 104.1954, -95.7129, 113.9213, 69.3451, 8.6753, -51.9253, 90.3563, 105.3188, 40.4897,
-102.5528, 138.2529, 121.7740, 30.8025, 21.7587, 108.2772, 53.6880, 35.2433, 10.4515, 100.9925)
)
# Make a leaflet map
leaflet(population_data) %>%
addTiles() %>%
addCircles(
lat = ~lat, lng = ~lng,
weight = 1, radius = ~population / 1000,
popup = ~paste(sep = "<br/>",
"<b>Country:</b>", country,
"<b>Population:</b>", population
),
color = "black", fill = TRUE, fillColor = "green", fillOpacity = 0.5
) %>%
setView(lng = 0, lat = 20, zoom = 2) %>%
htmlwidgets::onRender("function(el, x) {
el.style.width = '1000px'; } ")