This page has three leaflet maps, showing the top-5 cities in India by population, gross domestic product (GDP), and international tourist arrival (ITA).
library(leaflet)
library(xlsx)
population = read.xlsx("forLeaflet.xlsx", sheetName = "population")
str(population)
## 'data.frame': 5 obs. of 8 variables:
## $ city : Factor w/ 5 levels "Ahmedabad","Bangalore",..: 5 3 2 4 1
## $ population : num 12.44 11.03 8.44 6.99 5.58
## $ density : Factor w/ 3 levels "10 to 15","15 to 20",..: 3 1 2 1 1
## $ densitycolor: Factor w/ 3 levels "blue","green",..: 1 2 3 2 2
## $ literacy : num 89.7 86.2 87.7 83 88.3
## $ percapitagdp: Factor w/ 5 levels "$18,600","$5,051",..: 4 1 2 3 5
## $ lat : num 19.1 28.7 13 17.4 23
## $ lng : num 72.9 77.1 77.6 78.5 72.6
gdp = read.xlsx("forLeaflet.xlsx", sheetName = "gdp")
str(gdp)
## 'data.frame': 5 obs. of 6 variables:
## $ city : Factor w/ 5 levels "Bangalore","Chennai",..: 5 3 4 1 2
## $ gdp : num 310 293.6 150.1 110 78.6
## $ sector: Factor w/ 5 levels "Automotive Manufacturing",..: 2 4 5 3 1
## $ icon : Factor w/ 5 levels "Auto","BFSI",..: 2 4 5 3 1
## $ lat : num 19.1 28.7 22.6 13 13.1
## $ lng : num 72.9 77.1 88.4 77.6 80.3
tourism = read.xlsx("forLeaflet.xlsx", sheetName = "tourism")
str(tourism)
## 'data.frame': 35 obs. of 7 variables:
## $ city : Factor w/ 5 levels "Agra","Chennai",..: 3 3 3 3 3 3 3 3 3 3 ...
## $ attraction: Factor w/ 29 levels "Agra Fort","Albert Hall Museum",..: NA 25 17 22 12 13 24 23 21 15 ...
## $ icon : Factor w/ 30 levels "agrafort","alberthall",..: NA 26 18 23 12 13 25 24 22 15 ...
## $ iscity : logi TRUE FALSE FALSE FALSE FALSE FALSE ...
## $ ita : num 12.5 NA NA NA NA ...
## $ lat : num 28.7 28.7 28.6 28.5 28.6 ...
## $ lng : num 77.1 77.2 77.3 77.2 77.3 ...
Note: circle size proportionate to population size
Click on a city for popup with details
toppop = leaflet()
toppop = addTiles(toppop,
options = tileOptions(minZoom = 1, maxZoom = 4))
toppop = addCircleMarkers(toppop,
lng = population$lng,
lat = population$lat,
radius = population$population * 2,
color = as.character(population$densitycolor),
popup = paste(population$city,
"<br> Population: ",
round(population$population,2),
" million <br> Literacy Rate: ",
population$literacy,
"% <br> GDP per capita (PPP): ",
population$percapitagdp
)
)
toppop = addLegend(toppop,
position = "bottomright",
pal = colorFactor(
c("#0000ff", "#008000", "#ffa500"),
levels = unique(population$density)),
title = "Population Density ('000 per sq.km.)",
values = unique(population$density)
)
toppop
Note: circle size proportionate to GDP, custom icons show leading economic sector
Click on a city for popup with details
topgdp = leaflet()
topgdp = addTiles(topgdp,
options = tileOptions(minZoom = 1, maxZoom = 4))
topgdp = addCircleMarkers(topgdp,
lng = gdp$lng,
lat = gdp$lat,
radius = gdp$gdp/10 ,
popup = paste(gdp$city, "<br> GDP: $",
round(gdp$gdp,2), " billion <br>",
"Leading sector: ", gdp$sector,
"<br> GDP per capita (PPP): ",
population$percapitagdp
)
)
topgdp = addMarkers(topgdp,
lng = gdp$lng, lat = gdp$lat,
icon = makeIcon(iconUrl = paste("LocIcons/",
as.character(gdp$icon),
".png",sep=""
),
iconWidth = 30, iconHeight = 30
),
popup = paste(gdp$city, "<br> GDP: $",
round(gdp$gdp,2), " billion <br>",
"Leading sector: ", gdp$sector,
"<br> GDP per capita (PPP): ",
population$percapitagdp
)
)
topgdp
Note: labels show city name and latest annual ITA in millions
Click on clusters to zoom into multiple tourist attractions (custom icons with popups)
topita = leaflet()
topita = addTiles(topita)
topita = addMarkers(topita,
lng = tourism$lng[tourism$iscity == FALSE],
lat = tourism$lat[tourism$iscity == FALSE],
icon = makeIcon(iconUrl =
paste("LocIcons/",as.character(
tourism$icon[tourism$iscity == FALSE]),
".png",sep=""
),
iconWidth = 30, iconHeight = 30
),
popup = tourism$attraction[tourism$iscity == FALSE],
clusterOptions = markerClusterOptions()
)
topita = addMarkers(topita,
lng = tourism$lng[tourism$iscity == TRUE],
lat = tourism$lat[tourism$iscity == TRUE],
label = paste(tourism$city[tourism$iscity == TRUE],
round(tourism$ita[tourism$iscity==TRUE],1)),
labelOptions = labelOptions(noHide = TRUE,
opacity = 0.8,
direction = "right",
style=list("padding"="0px", "font-weight" = "bold"
)
),
icon = makeIcon(iconUrl = "LocIcons/Transparent.png",
iconWidth = 30, iconHeight = 30
)
)
topita
Data sources include:
1. Wikipedia
2. Business World
3. World Economic Forum
4. Government of Delhi
5. Euromonitor