The purpose of this project is to create a web page using R Markdown that features a map created with Leaflet. We will then host this as a webpage on RPubs. We will use the coordinates, population and area of India’s five largest metro cities for this demo.
metroData <- tbl_df(data.frame(city = c('New Delhi', 'Mumbai', 'Bangalore', 'Kolkatta', 'Chennai'),
latitude = c(28.704, 19.076, 12.972, 22.573, 13.083),
longitude = c(77.103, 72.878, 77.595, 88.364, 80.271),
population = c(12.79, 16.37, 5.69, 13.22, 6.43),
area = c(1484, 603, 709, 205, 426)))
The map below shows the five largest metro cities of India. The radius of the circle represents relative area of the cities while the fill opacity represents relative population density.
metroMap <- metroData %>%
leaflet() %>%
addTiles() %>%
addCircles(weight = 1,
radius = metroData$area * 200,
fillOpacity = 20 * metroData$population / metroData$area,
label = metroData$city)
metroMap