Data Input

covid_df = readxl::read_xlsx('MortalityDataWHR2021C2.xlsx') %>% 
  drop_na() %>% 
  janitor::clean_names() %>% 
  mutate(
    death_change = all_cause_death_count_2020 - all_cause_death_count_2019) 

covid_longer = covid_df %>% 
  pivot_longer(
    all_cause_death_count_2017:all_cause_death_count_2017,
    names_to = "year",
    names_prefix = "all_cause_death_count_",
    values_to = "death"
  ) %>% 
  mutate(year = as.numeric(year))

happy_df = readxl::read_xls('DataPanelWHR2021C2.xls') %>% 
  janitor::clean_names() %>% 
  select(1:3) %>% 
  subset(
    country_name != "Kosovo" & country_name != "Somaliland region"
  ) %>% 
  mutate(
    country_code = countrycode(country_name, "country.name", "iso3c")
  ) %>% 
  relocate(country_code) %>% 
  mutate(
    country_continent = countrycode(country_name, "country.name", "continent")
  ) %>% 
  relocate(country_continent) %>% 
  subset(year %in% c(2017,2018,2019,2020))

happy_df %>% 
  group_by(country_continent) %>% 
  summarize(n = n()) %>% 
  knitr::kable(col.names = c("Continent", "Number of Countries in Happiness Dataset"))
Continent Number of Countries in Happiness Dataset
Africa 138
Americas 77
Asia 150
Europe 151
Oceania 8
happy_wider = 
  happy_df %>% 
  pivot_wider(
    names_from = year,
    values_from = life_ladder,
    names_glue = "life_ladder_{year}"
  ) %>% 
  mutate(happy_change_2020 = life_ladder_2020 - life_ladder_2019,
         happy_change_2019 = life_ladder_2019 - life_ladder_2018) %>% 
  mutate(change_in_speed = happy_change_2020 - happy_change_2019)

covid_happy_trend = 
  left_join(covid_df, happy_wider, by = "country_name") %>% 
  drop_na()

COVID19 Distributions

covid_death_rate = covid_happy_trend %>% 
  plot_ly(x = ~country_name, 
         y = ~covid_19_deaths_per_100_000_population_in_2020,
         type = "bar", color = ~country_continent) %>% 
  layout(
    title = "COVID19 Deaths per 100,000 Population in 2020 in Each Country",
    xaxis = list(title = 'Country Name'),
    yaxis = list(title = 'COVID19 Deaths per 100,000 Population'))

covid_death_rate
covid_happy_trend %>% 
  group_by(country_continent) %>% 
  summarize(n = n()) %>% 
  knitr::kable(col.names = c("Continent", "Number of Countries in both Happiness and COVID Dataset"))
Continent Number of Countries in both Happiness and COVID Dataset
Africa 1
Americas 6
Asia 10
Europe 30
Oceania 1