This map showcases some of China’s top cities and their populations.
library(leaflet)
# Sample data for top cities
cities <- data.frame(
city = c("Shanghai", "Beijing", "Guangzhou", "Shenzhen", "Chongqing", "Tianjin", "Suzhou", "Chengdu", "Hangzhou", "Wuhan", "Nanjing", "Xi'an", "Changsha", "Qingdao", "Dalian", "Ningbo", "Xiamen", "Shenyang", "Zhengzhou", "Dongguan"),
lat = c(31.2304, 39.9042, 23.1291, 22.5431, 29.5630, 39.0842, 31.2989, 30.5729, 30.2741, 30.5858, 32.0602, 34.2638, 28.1941, 36.0661, 38.9140, 29.8684, 24.4798, 41.7967, 34.7472, 23.0201),
lng = c(121.4737, 116.4074, 113.2644, 114.0579, 106.5507, 117.1964, 120.6196, 104.0665, 120.1614, 114.3054, 118.7674, 108.9480, 112.9388, 120.3844, 121.6194, 121.5440, 118.1094, 123.4294, 113.6253, 113.7522),
population = c(24281400, 21536000, 15305900, 13438800, 31243200, 15618300, 10749900, 16581000, 10360000, 11212000, 8500000, 10203500, 8394500, 9499800, 5987000, 8542000, 4290000, 8316000, 10352000, 8464200)
)
# Create a color palette based on population
pal <- colorQuantile("YlOrRd", cities$population)
# Create the Leaflet map
leaflet(cities) %>%
addTiles() %>%
addCircles(lat = ~lat, lng = ~lng, weight = 1,
radius = ~sqrt(population) * 20, # Adjust the scaling factor as needed
color = ~pal(population),
popup = ~paste0(city, "<br>Population: ", population))
In this map, each city is represented by a circle whose size is proportional to its population. Hovering over a circle reveals the city name and its population.