This project involves the creation of a map of population in Australia in 2017 with Leaflet.
The data below were obtained from 50 Largest Cities in Australia and Australia Cities Coordinates.
Leaflet was first imported:
knitr::opts_chunk$set(warning=FALSE, echo=TRUE)
library(leaflet)
## Warning: package 'leaflet' was built under R version 4.0.2
A dataframe was created as a placeholder for the data as shown below:
aus <- data.frame(name=c("Sydney", "Melbourne", "Brisbane", "Perth", "Adelaide", "Gold Coast", "Newcastle", "Canberra", "Sunshine Coast", "Wollongong"),
pop=c(4741874, 4677157, 2326656, 2004696, 1315346, 663321, 481183, 447457, 325399, 299203),
lat=c(-33.865143, -37.840935, -27.470125, -31.953512, -34.921230, -28.016666, -32.916668, -35.282001, -26.650000, -34.425072),
lng=c(151.209900, 144.946457, 153.021072, 115.857048, 138.599503, 153.399994, 151.750000, 149.128998, 153.066666, 150.893143),
col=c("red", "red", "green", "green", "green", "green", "blue", "blue", "blue", "blue"))
The map was created as below. The size of each circle is proportional to the population of the city, while their colors represent the category of the population size as defined in the legend.
my_map <- aus %>%
leaflet() %>%
addTiles() %>%
addCircles(weight=1, radius=sqrt(aus$pop)*30, col=aus$col) %>%
addLegend(labels=c(">3,000,000", "50,000 - 3,000,000", "<50,000"), colors=c("red", "green", "blue"))
## Assuming "lng" and "lat" are longitude and latitude, respectively
my_map