knitr::opts_chunk$set(echo = TRUE)
library(leaflet)
library(dplyr)
library(countrycode)
library(rworldmap)
df <- readr::read_csv("2019.csv")
df$ISO3 <- countrycode(df$`Country or region`, "country.name", "iso3c")
pal <- colorNumeric(
palette = "RdYlBu",
domain = df$Score
)
map <- joinCountryData2Map(df, joinCode = "ISO3", nameJoinColumn = "ISO3", verbose = T)
## 155 codes from your data successfully matched countries in the map
## 1 codes from your data failed to match with a country code in the map
## failedCodes
## [1,] NA
## 89 codes from the map weren't represented in your data
Source
- This presentation uses the 2019 data from the World Happiness Report
- It can be downloaded here
Map of Happiness
leaflet(map) %>%
addTiles() %>%
addPolygons(weight=1,
fillColor = ~pal(Score),
fillOpacity = .9) %>%
addLegend(position = "topright",
pal = pal, values = df$Score,
title = "Happiness-Score",
opacity = 1
)