In this assignment we will map all world heritage sites registered with the UNESCO until the date of the creation of this page. The data is downloaded from the UNESCO official website https://whc.unesco.org/en/list/xls/?2021 on Jun.10th 2021. The map is created listing the sites, categorized as Cultural, Natural or Mixed. As you zoom in on different regions, you see all locations with its name and a brief description to help tourists locate them easily.
let’s first load packages:
library(leaflet)
library(readxl)
After you download the data, let’s read it into R and read it:
setwd("~/Desktop/futureskills/Predictive Analytics/Predictive Analytics/Developing data products/mine/")
whc_sites_2021 <- read_excel("~/Desktop/futureskills/Predictive Analytics/Predictive Analytics/Developing data products/mine/whc-sites-2021.xls")
summary(whc_sites_2021)
## unique_number id_no rev_bis name_en
## Min. : 4.0 Min. : 1.0 Length:1155 Length:1155
## 1st Qu.: 662.5 1st Qu.: 416.5 Class :character Class :character
## Median :1160.0 Median : 823.0 Mode :character Mode :character
## Mean :1224.5 Mean : 826.4
## 3rd Qu.:1856.0 3rd Qu.:1232.5
## Max. :2458.0 Max. :1654.0
##
## name_fr short_description_en short_description_fr
## Length:1155 Length:1155 Length:1155
## Class :character Class :character Class :character
## Mode :character Mode :character Mode :character
##
##
##
##
## justification_en justification_fr date_inscribed secondary_dates
## Length:1155 Length:1155 Min. :1978 Length:1155
## Class :character Class :character 1st Qu.:1988 Class :character
## Mode :character Mode :character Median :1998 Mode :character
## Mean :1999
## 3rd Qu.:2008
## Max. :2021
##
## danger date_end danger_list longitude
## Min. :0.00000 Min. :1988 Length:1155 Min. :-179.715
## 1st Qu.:0.00000 1st Qu.:2004 Class :character 1st Qu.: -3.273
## Median :0.00000 Median :2007 Mode :character Median : 16.314
## Mean :0.04502 Mean :2008 Mean : 20.622
## 3rd Qu.:0.00000 3rd Qu.:2014 3rd Qu.: 50.520
## Max. :1.00000 Max. :2021 Max. : 178.835
## NA's :1114
## latitude area_hectares C1 C2
## Min. :-54.59 Min. : 0 Min. :0.0000 Min. :0.0000
## 1st Qu.: 17.51 1st Qu.: 18 1st Qu.:0.0000 1st Qu.:0.0000
## Median : 36.13 Median : 228 Median :0.0000 Median :0.0000
## Mean : 28.99 Mean : 329892 Mean :0.2225 Mean :0.4017
## 3rd Qu.: 45.77 3rd Qu.: 14800 3rd Qu.:0.0000 3rd Qu.:1.0000
## Max. : 71.19 Max. :67296900 Max. :1.0000 Max. :1.0000
## NA's :20
## C3 C4 C5 C6
## Min. :0.0000 Min. :0.0000 Min. :0.0000 Min. :0.0000
## 1st Qu.:0.0000 1st Qu.:0.0000 1st Qu.:0.0000 1st Qu.:0.0000
## Median :0.0000 Median :1.0000 Median :0.0000 Median :0.0000
## Mean :0.4156 Mean :0.5316 Mean :0.1385 Mean :0.2147
## 3rd Qu.:1.0000 3rd Qu.:1.0000 3rd Qu.:0.0000 3rd Qu.:0.0000
## Max. :1.0000 Max. :1.0000 Max. :1.0000 Max. :1.0000
##
## N7 N8 N9 N10
## Min. :0.0000 Min. :0.00000 Min. :0.0000 Min. :0.0000
## 1st Qu.:0.0000 1st Qu.:0.00000 1st Qu.:0.0000 1st Qu.:0.0000
## Median :0.0000 Median :0.00000 Median :0.0000 Median :0.0000
## Mean :0.1264 Mean :0.08052 Mean :0.1126 Mean :0.1394
## 3rd Qu.:0.0000 3rd Qu.:0.00000 3rd Qu.:0.0000 3rd Qu.:0.0000
## Max. :1.0000 Max. :1.00000 Max. :1.0000 Max. :1.0000
##
## criteria_txt category category_short states_name_en
## Length:1155 Length:1155 Length:1155 Length:1155
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
##
##
##
##
## states_name_fr region_en region_fr iso_code
## Length:1155 Length:1155 Length:1155 Length:1155
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
##
##
##
##
## udnp_code transboundary
## Length:1155 Min. :0.00000
## Class :character 1st Qu.:0.00000
## Mode :character Median :0.00000
## Mean :0.03723
## 3rd Qu.:0.00000
## Max. :1.00000
##
Not all data is useful for our job. How about we create a new dataset -let’s call it sites- with the data we are going to use.
sites <- data.frame(latitude = c(whc_sites_2021$latitude), longitude = c(whc_sites_2021$longitude), name = c(whc_sites_2021$name_en), category = c(whc_sites_2021$category), desc = c(whc_sites_2021$short_description_en))
Now we are ready to create the map.
#We use awesome icons to create ones colored according to category
icons <- awesomeIcons(icon ="street-view", library = "fa", markerColor = sites$category, iconColor = "black")
#Now everything is ready let's create a map, cluster its numerous data points together, and color them.
# You can view the name of the site by hovering your mouse cursor over it; you can read its description by clicking the icon:
sites %>% leaflet() %>% addTiles() %>% addAwesomeMarkers(icon = icons, label = sites$name,labelOptions = labelOptions(opacity = 0.8, textsize = "14px", style = list(color = "red", 'font-style' = "italic")), clusterOptions = markerClusterOptions(maxClusterRadius = 50), popup = sites$desc)
## Assuming "longitude" and "latitude" are longitude and latitude, respectively