Create a web page using R Markdown that features a map created with Leaflet. Host your webpage on either GitHub Pages, RPubs, or NeoCities. Your webpage must contain the date that you created the document, and it must contain a map created with Leaflet. We would love to see you show off your creativity! I used the followed site: https://www.maxmind.com/en/free-world-cities-database
First, let’s load global cities open data.
setwd("D:/gilad/DataScience/Developing_Data_Products/Project1")
WorldCities <- read.csv(file = "worldcitiespop.csv", sep = ",")
The above dataset contains approximaty 1.5 million cities around the world. Hence, I will reduce it for only 30 cities on specific country. For example Grat Britain.
GBCities1 <- subset(WorldCities, Country == "gb")
GBCities1 <- head(GBCities1, 30)
GBCities1
## Country City AccentCity Region Population
## 986484 gb abberley Abberley Q4 NA
## 986485 gb abberton Abberton E4 NA
## 986486 gb abberton Abberton Q4 NA
## 986487 gb abbess roding Abbess Roding E4 NA
## 986488 gb abbey-cwmhir Abbey-Cwmhir Y8 NA
## 986489 gb abbey dore Abbey Dore F7 NA
## 986490 gb abbey saint bathans Abbey Saint Bathans T9 NA
## 986491 gb abbey town Abbey Town C9 NA
## 986492 gb abbots ann Abbots Ann F2 NA
## 986493 gb abbots bickington Abbots Bickington D4 NA
## 986494 gb abbots bromley Abbots Bromley N1 NA
## 986495 gb abbotsbury Abbotsbury D6 NA
## 986496 gb abbotsford Abbotsford T9 NA
## 986497 gb abbotsham Abbotsham D4 NA
## 986498 gb abbotskerswell Abbotskerswell D4 NA
## 986499 gb abbots langley Abbots Langley F8 NA
## 986500 gb abbots lench Abbots Lench Q4 NA
## 986501 gb abbotsley Abbotsley C3 NA
## 986502 gb abbots ripton Abbots Ripton C3 NA
## 986503 gb abbots worthy Abbots Worthy F2 NA
## 986504 gb abbotts ann Abbotts Ann F2 NA
## 986505 gb abbotts ripton Abbotts Ripton C3 NA
## 986506 gb aber Aber Y2 NA
## 986507 gb aberaeron Aberaeron X6 NA
## 986508 gb aberaman Aberaman Y9 NA
## 986509 gb aberangell Aberangell Y8 NA
## 986510 gb aberarder Aberarder V3 NA
## 986511 gb aberargie Aberargie W1 NA
## 986512 gb aber-arth Aber-Arth X6 NA
## 986513 gb aberayron Aberayron X6 NA
## Latitude Longitude
## 986484 52.30000 -2.366667
## 986485 51.83333 0.916667
## 986486 52.18333 -2.016667
## 986487 51.78333 0.266667
## 986488 52.33333 -3.400000
## 986489 51.96667 -2.900000
## 986490 55.85000 -2.383333
## 986491 54.83333 -3.283333
## 986492 51.18333 -1.516667
## 986493 50.90000 -4.283333
## 986494 52.80000 -1.866667
## 986495 50.66667 -2.600000
## 986496 55.60000 -2.783333
## 986497 51.01667 -4.250000
## 986498 50.50000 -3.616667
## 986499 51.70000 -0.416667
## 986500 52.15000 -1.966667
## 986501 52.18333 -0.200000
## 986502 52.38333 -0.183333
## 986503 51.08333 -1.283333
## 986504 51.18333 -1.516667
## 986505 52.38333 -0.183333
## 986506 53.23333 -4.016667
## 986507 52.25000 -4.250000
## 986508 51.69889 -3.426944
## 986509 52.66667 -3.716667
## 986510 57.30000 -4.266667
## 986511 56.31667 -3.350000
## 986512 52.25000 -4.233333
## 986513 52.25000 -4.250000
Now, we will display GB cities on map with a single flag.
library(leaflet)
## Warning: package 'leaflet' was built under R version 3.4.4
GBIcon <- makeIcon(
iconUrl = "http://icons.iconarchive.com/icons/pan-tera/flags/128/Great-Britain-Flag-icon.png",
iconWidth = 31*215/230, iconHeight = 31,
iconAnchorX = 31*215/230/2, iconAnchorY = 16
)
df <- data.frame(lat = GBCities1$Latitude,
lng = GBCities1$Longitude)
df %>%
leaflet() %>%
addTiles() %>%
addMarkers(icon = GBIcon)
Let’s add some markers clustering as well.
df <- data.frame(lat = GBCities1$Latitude,
lng = GBCities1$Longitude)
df %>%
leaflet() %>%
addTiles() %>%
addMarkers(clusterOptions = markerClusterOptions())