knitr::opts_chunk$set(
warning = FALSE,
message = FALSE)
#data cleans and joins
#adding the data
happiness <- read_excel(here::here("data_raw", 'happinessdata.xls'))
income_inequality <- read_csv(here::here('data_raw',"gini.csv"))
PPP <- read_excel(here::here("data_raw", "PPP.xls"), sheet="Data", skip=3)
PPPP <- read_excel(here::here("data_raw", "PPPP.xls"), sheet="Data", skip=3)
counrty_region <- read_excel(here::here("data_raw", "PPP.xls"), sheet="Metadata - Countries")
#clean happiness names
happiness <- happiness %>%
clean_names()
#clean country regions
counrty_region_clean <- counrty_region %>%
clean_names() %>%
select(-special_notes, -table_name)
#clean happiness with selected variables I think I got them all but you may need to check
happiness_clean<- happiness %>%
filter(!is.na(life_ladder)) %>%
select(country_name, year, life_ladder, log_gdp_per_capita, social_support, healthy_life_expectancy_at_birth, freedom_to_make_life_choices,generosity,perceptions_of_corruption,positive_affect,negative_affect,confidence_in_national_government,democratic_quality)
#ppp clean
#glimpse(PPP)
PPP_clean <- PPP %>%
gather(key='year', value='ppp', "1960":"2019") %>%
mutate(year=as.numeric(year)) %>%
filter(year>2005) %>%
clean_names() %>%
select(-indicator_name, -indicator_code) %>%
filter(!is.na(ppp))
#glimpse(PPP_clean)
#pppp clean
PPPP_clean <- PPPP %>%
gather(key='year', value='pppp', "1960":"2019") %>%
mutate(year=as.numeric(year)) %>%
filter(year>2005) %>%
clean_names() %>%
select(-indicator_name, -indicator_code) %>%
filter(!is.na(pppp))
#glimpse(PPPP_clean)
#income inequality join with happiness
glimpse(income_inequality)
## Observations: 195
## Variables: 242
## $ country <chr> "Afghanistan", "Albania", "Algeria", "Andorra", "Angola"…
## $ `1800` <dbl> 30.5, 38.9, 56.2, 40.0, 57.2, 40.0, 47.7, 31.5, 38.7, 33…
## $ `1801` <dbl> 30.5, 38.9, 56.2, 40.0, 57.2, 40.0, 47.7, 31.5, 38.7, 33…
## $ `1802` <dbl> 30.5, 38.9, 56.2, 40.0, 57.2, 40.0, 47.7, 31.5, 38.7, 33…
## $ `1803` <dbl> 30.5, 38.9, 56.2, 40.0, 57.2, 40.0, 47.7, 31.5, 38.7, 33…
## $ `1804` <dbl> 30.5, 38.9, 56.2, 40.0, 57.2, 40.0, 47.7, 31.5, 38.7, 33…
## $ `1805` <dbl> 30.5, 38.9, 56.2, 40.0, 57.2, 40.0, 47.7, 31.5, 38.7, 33…
## $ `1806` <dbl> 30.5, 38.9, 56.2, 40.0, 57.2, 40.0, 47.7, 31.5, 38.7, 33…
## $ `1807` <dbl> 30.5, 38.9, 56.2, 40.0, 57.2, 40.0, 47.7, 31.5, 38.7, 33…
## $ `1808` <dbl> 30.5, 38.9, 56.2, 40.0, 57.2, 40.0, 47.7, 31.5, 38.7, 33…
## $ `1809` <dbl> 30.5, 38.9, 56.2, 40.0, 57.2, 40.0, 47.7, 31.5, 38.7, 33…
## $ `1810` <dbl> 30.5, 38.9, 56.2, 40.0, 57.2, 40.0, 47.7, 31.5, 38.7, 33…
## $ `1811` <dbl> 30.5, 38.9, 56.2, 40.0, 57.2, 40.0, 47.7, 31.5, 38.7, 33…
## $ `1812` <dbl> 30.5, 38.9, 56.2, 40.0, 57.2, 40.0, 47.7, 31.5, 38.7, 33…
## $ `1813` <dbl> 30.5, 38.9, 56.2, 40.0, 57.2, 40.0, 47.7, 31.5, 38.7, 33…
## $ `1814` <dbl> 30.5, 38.9, 56.2, 40.0, 57.2, 40.0, 47.7, 31.5, 38.7, 33…
## $ `1815` <dbl> 30.5, 38.9, 56.2, 40.0, 57.2, 40.0, 47.7, 31.5, 38.7, 33…
## $ `1816` <dbl> 30.5, 38.9, 56.2, 40.0, 57.2, 40.0, 47.7, 31.5, 38.7, 33…
## $ `1817` <dbl> 30.5, 38.9, 56.2, 40.0, 57.2, 40.0, 47.6, 31.5, 38.7, 33…
## $ `1818` <dbl> 30.5, 38.9, 56.3, 40.0, 57.1, 40.0, 47.5, 31.5, 38.7, 33…
## $ `1819` <dbl> 30.5, 38.9, 56.4, 40.0, 56.9, 40.0, 47.3, 31.5, 38.7, 33…
## $ `1820` <dbl> 30.5, 38.9, 56.5, 40.0, 56.8, 40.0, 47.1, 31.5, 38.7, 32…
## $ `1821` <dbl> 30.5, 38.9, 56.6, 40.0, 56.6, 40.0, 46.8, 31.5, 38.7, 32…
## $ `1822` <dbl> 30.5, 38.9, 56.7, 40.0, 56.4, 40.0, 46.5, 31.5, 38.7, 32…
## $ `1823` <dbl> 30.5, 38.9, 56.8, 40.0, 56.1, 40.0, 46.2, 31.5, 38.7, 32…
## $ `1824` <dbl> 30.5, 38.9, 56.9, 40.0, 55.9, 40.0, 45.8, 31.5, 38.7, 31…
## $ `1825` <dbl> 30.5, 38.9, 57.0, 40.0, 55.7, 40.0, 45.6, 31.5, 38.7, 31…
## $ `1826` <dbl> 30.5, 38.9, 57.2, 40.0, 55.4, 40.0, 45.2, 31.5, 38.7, 31…
## $ `1827` <dbl> 30.5, 38.9, 57.4, 40.0, 55.1, 40.0, 44.8, 31.5, 38.7, 31…
## $ `1828` <dbl> 30.5, 38.9, 57.5, 40.0, 54.7, 40.0, 44.3, 31.5, 38.7, 30…
## $ `1829` <dbl> 30.5, 38.9, 57.7, 40.0, 54.4, 40.0, 43.9, 31.5, 38.7, 30…
## $ `1830` <dbl> 30.5, 38.9, 57.9, 40.0, 54.1, 40.0, 43.4, 31.5, 38.7, 29…
## $ `1831` <dbl> 30.5, 38.9, 58.1, 40.0, 53.7, 40.0, 42.9, 31.5, 38.7, 29…
## $ `1832` <dbl> 30.5, 38.9, 58.2, 40.0, 53.4, 40.0, 42.5, 31.5, 38.7, 29…
## $ `1833` <dbl> 30.5, 38.9, 58.4, 40.0, 53.1, 40.0, 42.0, 31.5, 38.7, 28…
## $ `1834` <dbl> 30.5, 38.9, 58.6, 40.0, 52.7, 40.0, 41.6, 31.5, 38.7, 28…
## $ `1835` <dbl> 30.5, 38.9, 58.8, 40.0, 52.4, 40.0, 41.1, 31.5, 38.7, 28…
## $ `1836` <dbl> 30.5, 38.9, 58.9, 40.0, 52.1, 40.0, 40.7, 31.5, 38.7, 27…
## $ `1837` <dbl> 30.5, 38.9, 59.1, 40.0, 51.7, 40.0, 40.2, 31.5, 38.7, 27…
## $ `1838` <dbl> 30.5, 38.9, 59.3, 40.0, 51.4, 40.0, 39.8, 31.5, 38.7, 27…
## $ `1839` <dbl> 30.5, 38.9, 59.5, 40.0, 51.1, 40.0, 39.3, 31.5, 38.7, 26…
## $ `1840` <dbl> 30.5, 38.9, 59.6, 40.0, 50.7, 40.0, 38.9, 31.5, 38.7, 26…
## $ `1841` <dbl> 30.5, 38.9, 59.8, 40.0, 50.4, 40.0, 38.4, 31.5, 38.7, 26…
## $ `1842` <dbl> 30.5, 38.9, 60.0, 40.0, 50.1, 40.0, 38.0, 31.5, 38.7, 25…
## $ `1843` <dbl> 30.5, 38.9, 60.2, 40.0, 49.7, 40.0, 37.5, 31.5, 38.7, 25…
## $ `1844` <dbl> 30.6, 38.9, 60.3, 40.0, 49.4, 40.0, 37.1, 31.5, 38.7, 24…
## $ `1845` <dbl> 30.7, 38.9, 60.4, 40.0, 49.1, 40.0, 36.7, 31.7, 38.7, 24…
## $ `1846` <dbl> 30.9, 38.9, 60.5, 40.0, 48.7, 40.0, 36.5, 31.9, 38.8, 24…
## $ `1847` <dbl> 31.2, 38.9, 60.4, 40.0, 48.4, 40.0, 36.3, 32.3, 38.8, 24…
## $ `1848` <dbl> 31.5, 38.9, 60.3, 40.0, 48.1, 40.0, 36.2, 32.7, 38.9, 23…
## $ `1849` <dbl> 31.9, 38.9, 60.1, 40.0, 47.7, 40.0, 36.3, 33.3, 39.0, 23…
## $ `1850` <dbl> 32.4, 38.9, 59.8, 40.0, 47.4, 40.0, 36.4, 34.0, 39.1, 23…
## $ `1851` <dbl> 33.0, 38.9, 59.4, 40.0, 47.1, 40.0, 36.7, 34.8, 39.3, 23…
## $ `1852` <dbl> 33.6, 38.9, 59.0, 40.0, 46.7, 40.0, 37.0, 35.8, 39.5, 23…
## $ `1853` <dbl> 34.3, 38.9, 58.5, 40.0, 46.4, 40.0, 37.5, 36.8, 39.6, 22…
## $ `1854` <dbl> 35.0, 38.9, 57.9, 40.0, 46.1, 40.0, 38.0, 38.0, 39.8, 22…
## $ `1855` <dbl> 35.8, 38.9, 57.2, 40.0, 45.7, 40.0, 38.6, 39.3, 40.1, 22…
## $ `1856` <dbl> 36.7, 38.9, 56.5, 40.0, 45.4, 40.0, 39.4, 40.7, 40.3, 22…
## $ `1857` <dbl> 37.7, 38.9, 55.7, 40.0, 45.1, 40.0, 40.2, 42.3, 40.6, 22…
## $ `1858` <dbl> 38.6, 38.9, 54.8, 40.0, 44.7, 40.0, 41.1, 43.9, 40.9, 22…
## $ `1859` <dbl> 39.6, 38.9, 53.9, 40.0, 44.4, 40.0, 42.1, 45.5, 41.2, 22…
## $ `1860` <dbl> 40.5, 38.9, 53.0, 40.0, 44.1, 40.0, 43.0, 47.2, 41.5, 22…
## $ `1861` <dbl> 41.5, 38.9, 52.1, 40.0, 43.7, 40.0, 44.0, 48.8, 41.8, 22…
## $ `1862` <dbl> 42.4, 38.9, 51.2, 40.0, 43.4, 40.0, 44.9, 50.5, 42.1, 22…
## $ `1863` <dbl> 43.4, 38.9, 50.3, 40.0, 43.1, 40.0, 45.8, 52.1, 42.4, 22…
## $ `1864` <dbl> 44.3, 38.9, 49.4, 40.0, 42.7, 40.0, 46.8, 53.8, 42.6, 22…
## $ `1865` <dbl> 45.0, 38.9, 48.5, 40.0, 42.4, 40.0, 47.6, 55.2, 42.9, 22…
## $ `1866` <dbl> 45.7, 38.8, 47.7, 40.0, 42.1, 40.0, 48.4, 56.4, 43.1, 22…
## $ `1867` <dbl> 46.2, 38.7, 46.9, 40.0, 41.7, 40.0, 49.0, 57.4, 43.2, 22…
## $ `1868` <dbl> 46.7, 38.5, 46.1, 40.0, 41.4, 40.0, 49.6, 58.2, 43.3, 22…
## $ `1869` <dbl> 47.0, 38.3, 45.3, 40.0, 41.1, 40.0, 50.0, 58.7, 43.4, 22…
## $ `1870` <dbl> 47.2, 38.0, 44.5, 40.0, 40.7, 40.0, 50.4, 59.0, 43.4, 22…
## $ `1871` <dbl> 47.3, 37.7, 43.8, 40.0, 40.4, 40.0, 50.7, 59.1, 43.3, 22…
## $ `1872` <dbl> 47.2, 37.4, 43.1, 40.0, 40.1, 40.0, 50.9, 59.0, 43.2, 22…
## $ `1873` <dbl> 47.1, 37.0, 42.4, 40.0, 39.7, 40.0, 51.0, 58.7, 43.1, 22…
## $ `1874` <dbl> 46.8, 36.6, 41.8, 40.0, 39.4, 40.0, 50.9, 58.1, 42.9, 22…
## $ `1875` <dbl> 46.4, 36.1, 41.1, 40.0, 39.1, 40.0, 50.8, 57.3, 42.7, 22…
## $ `1876` <dbl> 45.9, 35.6, 40.5, 40.0, 38.7, 40.0, 50.7, 56.3, 42.4, 22…
## $ `1877` <dbl> 45.3, 35.0, 39.9, 40.0, 38.4, 40.0, 50.4, 55.1, 42.0, 22…
## $ `1878` <dbl> 44.7, 34.4, 39.4, 40.0, 38.1, 40.0, 50.0, 53.6, 41.7, 22…
## $ `1879` <dbl> 44.0, 33.8, 38.8, 40.0, 37.7, 40.0, 49.6, 52.2, 41.3, 22…
## $ `1880` <dbl> 43.4, 33.2, 38.2, 40.0, 37.4, 40.0, 49.2, 50.7, 40.9, 22…
## $ `1881` <dbl> 42.7, 32.6, 37.7, 40.0, 37.1, 40.0, 48.8, 49.3, 40.5, 22…
## $ `1882` <dbl> 42.1, 31.9, 37.1, 40.0, 36.7, 40.0, 48.4, 47.8, 40.1, 22…
## $ `1883` <dbl> 41.4, 31.3, 36.6, 40.0, 36.4, 40.0, 48.1, 46.4, 39.7, 22…
## $ `1884` <dbl> 40.8, 30.7, 36.0, 40.0, 36.1, 40.0, 47.7, 44.9, 39.4, 22…
## $ `1885` <dbl> 40.2, 30.2, 35.5, 40.0, 35.8, 40.0, 47.3, 43.6, 39.0, 22…
## $ `1886` <dbl> 39.7, 29.6, 35.0, 40.0, 35.6, 40.0, 47.0, 42.4, 38.7, 22…
## $ `1887` <dbl> 39.2, 29.2, 34.6, 40.0, 35.5, 40.0, 46.8, 41.3, 38.4, 22…
## $ `1888` <dbl> 38.8, 28.7, 34.3, 40.0, 35.5, 40.0, 46.6, 40.3, 38.1, 22…
## $ `1889` <dbl> 38.5, 28.3, 34.0, 40.0, 35.5, 40.0, 46.5, 39.5, 37.9, 23…
## $ `1890` <dbl> 38.3, 28.0, 33.7, 40.0, 35.6, 40.0, 46.4, 38.7, 37.7, 23…
## $ `1891` <dbl> 38.1, 27.6, 33.5, 40.0, 35.8, 40.0, 46.4, 38.1, 37.6, 23…
## $ `1892` <dbl> 38.0, 27.4, 33.3, 40.0, 36.0, 40.0, 46.4, 37.6, 37.4, 23…
## $ `1893` <dbl> 38.0, 27.1, 33.2, 40.0, 36.4, 40.0, 46.4, 37.2, 37.3, 23…
## $ `1894` <dbl> 38.0, 26.9, 33.2, 40.0, 36.8, 40.0, 46.5, 37.0, 37.3, 23…
## $ `1895` <dbl> 38.1, 26.8, 33.2, 40.0, 37.2, 40.0, 46.7, 36.8, 37.3, 23…
## $ `1896` <dbl> 38.2, 26.7, 33.3, 40.0, 37.8, 40.0, 46.9, 36.8, 37.3, 23…
## $ `1897` <dbl> 38.5, 26.6, 33.4, 40.0, 38.4, 40.0, 47.1, 36.9, 37.3, 23…
## $ `1898` <dbl> 38.8, 26.6, 33.5, 40.0, 39.1, 40.0, 47.5, 37.1, 37.4, 23…
## $ `1899` <dbl> 39.1, 26.5, 33.7, 40.0, 39.8, 40.0, 47.8, 37.4, 37.4, 23…
## $ `1900` <dbl> 39.4, 26.5, 33.8, 40.0, 40.5, 40.0, 48.1, 37.6, 37.5, 23…
## $ `1901` <dbl> 39.7, 26.5, 34.0, 40.0, 41.2, 40.0, 48.4, 37.8, 37.5, 23…
## $ `1902` <dbl> 39.9, 26.4, 34.2, 40.0, 41.9, 40.0, 48.7, 38.0, 37.6, 23…
## $ `1903` <dbl> 40.2, 26.4, 34.3, 40.0, 42.6, 40.0, 49.0, 38.3, 37.7, 23…
## $ `1904` <dbl> 40.5, 26.4, 34.5, 40.0, 43.3, 40.0, 49.3, 38.5, 37.7, 23…
## $ `1905` <dbl> 40.8, 26.3, 34.6, 40.0, 44.0, 40.0, 49.5, 38.7, 37.8, 23…
## $ `1906` <dbl> 41.0, 26.3, 34.8, 40.0, 44.7, 40.0, 49.8, 38.9, 37.8, 23…
## $ `1907` <dbl> 41.2, 26.3, 35.0, 40.0, 45.4, 40.0, 49.9, 39.1, 37.8, 23…
## $ `1908` <dbl> 41.3, 26.3, 35.2, 40.0, 46.1, 40.0, 50.1, 39.2, 37.8, 23…
## $ `1909` <dbl> 41.5, 26.3, 35.3, 40.0, 46.8, 40.0, 50.2, 39.4, 37.8, 23…
## $ `1910` <dbl> 41.5, 26.2, 35.5, 40.0, 47.5, 40.0, 50.2, 39.5, 37.7, 23…
## $ `1911` <dbl> 41.5, 26.2, 35.7, 40.0, 48.3, 40.0, 50.2, 39.6, 37.6, 23…
## $ `1912` <dbl> 41.5, 26.2, 35.9, 40.0, 49.0, 40.0, 50.2, 39.7, 37.5, 23…
## $ `1913` <dbl> 41.5, 26.2, 36.0, 40.0, 49.7, 40.0, 50.2, 39.8, 37.4, 23…
## $ `1914` <dbl> 41.4, 26.2, 36.2, 40.0, 50.4, 40.0, 50.0, 39.9, 37.3, 23…
## $ `1915` <dbl> 41.3, 26.2, 36.4, 40.0, 51.2, 40.0, 49.9, 40.0, 37.1, 23…
## $ `1916` <dbl> 41.1, 26.2, 36.6, 40.0, 51.9, 40.0, 49.7, 40.0, 36.7, 23…
## $ `1917` <dbl> 40.9, 26.2, 36.8, 40.0, 52.7, 40.0, 49.5, 40.1, 36.6, 23…
## $ `1918` <dbl> 40.6, 26.2, 37.0, 40.0, 53.4, 40.0, 49.2, 40.1, 36.4, 23…
## $ `1919` <dbl> 40.4, 26.2, 37.2, 40.0, 54.2, 40.0, 48.9, 40.1, 36.2, 23…
## $ `1920` <dbl> 40.2, 26.3, 37.4, 40.0, 54.9, 40.0, 48.6, 40.1, 35.9, 23…
## $ `1921` <dbl> 39.9, 26.3, 37.6, 40.0, 55.7, 40.0, 48.3, 40.1, 35.8, 23…
## $ `1922` <dbl> 39.7, 26.3, 37.8, 40.0, 56.4, 40.0, 48.1, 40.2, 35.8, 23…
## $ `1923` <dbl> 39.4, 26.3, 38.0, 40.0, 57.2, 40.0, 47.8, 40.2, 35.5, 23…
## $ `1924` <dbl> 39.2, 26.3, 38.2, 40.0, 57.9, 40.0, 47.5, 40.2, 35.0, 23…
## $ `1925` <dbl> 39.0, 26.3, 38.3, 40.0, 58.5, 40.0, 47.2, 40.2, 34.4, 23…
## $ `1926` <dbl> 38.7, 26.3, 38.5, 40.0, 59.0, 40.0, 47.0, 40.3, 33.8, 23…
## $ `1927` <dbl> 38.5, 26.3, 38.7, 40.0, 59.5, 40.0, 46.6, 40.3, 33.5, 23…
## $ `1928` <dbl> 38.3, 26.3, 38.8, 40.0, 59.9, 40.0, 46.3, 40.3, 33.2, 23…
## $ `1929` <dbl> 38.0, 26.3, 38.9, 40.0, 60.2, 40.0, 46.1, 40.3, 33.0, 23…
## $ `1930` <dbl> 37.8, 26.4, 39.0, 40.0, 60.4, 40.0, 46.0, 40.3, 33.1, 23…
## $ `1931` <dbl> 37.6, 26.4, 39.1, 40.0, 60.6, 40.0, 46.0, 40.4, 32.7, 23…
## $ `1932` <dbl> 37.4, 26.4, 39.2, 40.0, 60.7, 40.0, 46.1, 40.4, 32.4, 23…
## $ `1933` <dbl> 37.1, 26.4, 39.3, 40.0, 60.7, 40.0, 46.1, 40.4, 32.3, 23…
## $ `1934` <dbl> 36.9, 26.4, 39.3, 40.0, 60.7, 40.0, 46.2, 40.4, 32.1, 23…
## $ `1935` <dbl> 36.7, 26.4, 39.4, 40.0, 60.7, 40.0, 46.0, 40.4, 31.3, 23…
## $ `1936` <dbl> 36.5, 26.4, 39.4, 40.0, 60.4, 40.0, 46.2, 40.5, 31.5, 23…
## $ `1937` <dbl> 36.3, 26.4, 39.4, 40.0, 60.1, 40.0, 46.7, 40.5, 31.9, 23…
## $ `1938` <dbl> 36.1, 26.4, 39.4, 40.0, 59.9, 40.0, 47.3, 40.5, 32.2, 23…
## $ `1939` <dbl> 35.9, 26.4, 39.4, 40.0, 59.6, 40.0, 48.5, 40.5, 32.3, 23…
## $ `1940` <dbl> 35.7, 26.5, 39.4, 40.0, 59.4, 40.0, 49.5, 40.6, 31.9, 23…
## $ `1941` <dbl> 35.5, 26.5, 39.5, 40.0, 59.1, 40.0, 50.1, 40.6, 31.2, 23…
## $ `1942` <dbl> 35.2, 26.5, 39.5, 40.0, 58.9, 40.0, 50.4, 40.6, 30.7, 23…
## $ `1943` <dbl> 35.0, 26.5, 39.5, 40.0, 58.6, 40.0, 50.9, 40.6, 30.9, 23…
## $ `1944` <dbl> 34.8, 26.5, 39.5, 40.0, 58.4, 40.0, 51.3, 40.6, 31.1, 23…
## $ `1945` <dbl> 34.6, 26.5, 39.5, 40.0, 58.1, 40.0, 51.1, 40.7, 31.2, 23…
## $ `1946` <dbl> 34.4, 26.5, 39.5, 40.0, 57.9, 40.0, 51.0, 40.7, 32.4, 23…
## $ `1947` <dbl> 34.3, 26.5, 39.5, 40.0, 57.6, 40.0, 50.3, 40.7, 32.7, 23…
## $ `1948` <dbl> 34.2, 26.5, 39.6, 40.0, 57.4, 40.0, 49.2, 40.7, 33.1, 23…
## $ `1949` <dbl> 34.1, 26.5, 39.6, 40.0, 57.2, 40.0, 47.7, 40.7, 33.4, 23…
## $ `1950` <dbl> 34.0, 26.6, 39.6, 40.0, 57.0, 40.0, 46.4, 40.8, 35.1, 24…
## $ `1951` <dbl> 34.0, 26.6, 39.6, 40.0, 56.8, 40.0, 45.7, 40.8, 35.8, 24…
## $ `1952` <dbl> 34.0, 26.6, 39.6, 40.0, 56.6, 40.0, 44.7, 40.8, 36.2, 24…
## $ `1953` <dbl> 34.1, 26.6, 39.6, 40.0, 56.5, 40.0, 43.6, 40.8, 36.5, 25…
## $ `1954` <dbl> 34.3, 26.6, 39.7, 40.0, 56.4, 40.0, 42.9, 40.9, 36.5, 25…
## $ `1955` <dbl> 34.4, 26.6, 39.7, 40.0, 56.3, 40.0, 41.9, 40.9, 35.4, 26…
## $ `1956` <dbl> 34.5, 26.6, 39.7, 40.0, 56.2, 40.0, 42.0, 40.9, 35.2, 27…
## $ `1957` <dbl> 34.6, 26.6, 39.7, 40.0, 56.1, 40.0, 42.2, 40.9, 35.2, 27…
## $ `1958` <dbl> 34.6, 26.6, 39.7, 40.0, 56.0, 40.0, 42.4, 40.9, 35.2, 28…
## $ `1959` <dbl> 34.5, 26.6, 39.7, 40.0, 55.9, 40.0, 41.9, 41.0, 35.3, 28…
## $ `1960` <dbl> 34.4, 26.7, 39.7, 40.0, 55.8, 40.0, 41.4, 41.0, 35.2, 29…
## $ `1961` <dbl> 34.1, 26.7, 39.8, 40.0, 55.7, 40.0, 41.4, 41.0, 35.3, 29…
## $ `1962` <dbl> 33.7, 26.7, 39.8, 40.0, 55.6, 40.0, 41.5, 41.0, 35.4, 29…
## $ `1963` <dbl> 33.2, 26.7, 39.8, 40.0, 55.5, 40.0, 40.7, 41.1, 35.2, 29…
## $ `1964` <dbl> 32.7, 26.7, 39.8, 40.0, 55.4, 40.0, 40.0, 41.1, 35.1, 29…
## $ `1965` <dbl> 32.2, 26.7, 39.8, 40.0, 55.3, 40.0, 39.4, 41.1, 35.1, 29…
## $ `1966` <dbl> 31.7, 26.7, 39.8, 40.0, 55.2, 40.0, 38.8, 41.1, 34.8, 29…
## $ `1967` <dbl> 31.2, 26.7, 39.9, 40.0, 55.2, 40.0, 38.2, 41.1, 34.7, 29…
## $ `1968` <dbl> 30.8, 26.7, 39.9, 40.0, 55.1, 40.0, 37.6, 41.2, 34.5, 29…
## $ `1969` <dbl> 30.5, 26.7, 39.9, 40.0, 54.9, 40.0, 36.7, 41.2, 34.2, 29…
## $ `1970` <dbl> 30.5, 26.8, 39.9, 40.0, 54.8, 40.0, 36.1, 41.2, 33.8, 29…
## $ `1971` <dbl> 30.8, 26.8, 39.9, 40.0, 54.7, 40.0, 35.6, 41.2, 33.6, 29…
## $ `1972` <dbl> 31.2, 26.8, 39.9, 40.0, 54.6, 40.0, 35.3, 41.3, 33.4, 28…
## $ `1973` <dbl> 31.6, 26.8, 40.0, 40.0, 54.5, 40.0, 35.2, 41.3, 33.3, 28…
## $ `1974` <dbl> 31.9, 26.8, 40.0, 40.0, 54.4, 40.0, 35.5, 41.3, 33.2, 27…
## $ `1975` <dbl> 32.1, 26.8, 40.0, 40.0, 54.4, 40.0, 36.1, 41.3, 33.1, 27…
## $ `1976` <dbl> 32.2, 26.8, 40.0, 40.0, 54.3, 40.0, 36.9, 41.3, 33.1, 26…
## $ `1977` <dbl> 32.2, 26.8, 40.0, 40.0, 54.2, 40.0, 37.9, 41.4, 33.0, 26…
## $ `1978` <dbl> 32.2, 26.8, 40.0, 40.0, 54.1, 40.0, 38.8, 41.4, 32.8, 25…
## $ `1979` <dbl> 32.2, 26.8, 40.1, 40.0, 54.0, 40.0, 39.7, 41.4, 32.5, 25…
## $ `1980` <dbl> 32.2, 26.9, 40.1, 40.0, 53.9, 40.0, 40.4, 41.4, 32.2, 24…
## $ `1981` <dbl> 32.1, 26.9, 40.1, 40.0, 53.8, 40.0, 41.0, 41.5, 32.0, 24…
## $ `1982` <dbl> 32.0, 26.9, 40.1, 40.0, 53.7, 40.0, 41.5, 41.5, 31.9, 24…
## $ `1983` <dbl> 32.1, 26.9, 40.1, 40.0, 53.6, 40.0, 41.8, 41.5, 31.9, 24…
## $ `1984` <dbl> 32.5, 26.9, 40.1, 40.0, 53.5, 40.0, 42.1, 41.5, 32.2, 25…
## $ `1985` <dbl> 33.0, 26.9, 40.1, 40.0, 53.4, 40.0, 42.9, 41.5, 32.4, 26…
## $ `1986` <dbl> 33.7, 26.9, 40.2, 40.0, 53.3, 40.0, 43.7, 41.6, 32.6, 26…
## $ `1987` <dbl> 34.7, 26.9, 40.0, 40.0, 53.2, 40.0, 44.5, 41.6, 32.8, 27…
## $ `1988` <dbl> 35.4, 26.9, 39.8, 40.0, 53.1, 40.0, 45.3, 41.6, 32.9, 28…
## $ `1989` <dbl> 36.0, 26.9, 39.4, 40.0, 53.0, 40.0, 46.1, 41.7, 33.0, 28…
## $ `1990` <dbl> 36.4, 27.0, 38.8, 40.0, 52.9, 40.0, 46.1, 41.9, 33.0, 28…
## $ `1991` <dbl> 36.7, 27.0, 38.1, 40.0, 52.8, 40.0, 45.9, 42.2, 33.0, 28…
## $ `1992` <dbl> 36.7, 27.0, 37.4, 40.0, 52.8, 40.0, 45.9, 42.6, 32.9, 27…
## $ `1993` <dbl> 36.8, 27.0, 36.7, 40.0, 52.7, 40.0, 46.4, 43.0, 32.8, 27…
## $ `1994` <dbl> 36.8, 27.0, 36.1, 40.0, 52.6, 40.0, 46.9, 43.5, 32.7, 27…
## $ `1995` <dbl> 36.8, 27.2, 35.5, 40.0, 52.5, 40.0, 47.7, 43.3, 32.7, 27…
## $ `1996` <dbl> 36.8, 27.5, 34.9, 40.0, 52.4, 40.0, 48.8, 42.5, 32.8, 27…
## $ `1997` <dbl> 36.8, 28.0, 34.4, 40.0, 52.3, 40.0, 49.6, 41.0, 32.9, 27…
## $ `1998` <dbl> 36.8, 28.6, 34.0, 40.0, 52.2, 40.0, 50.0, 39.4, 33.0, 27…
## $ `1999` <dbl> 36.8, 29.4, 33.5, 40.0, 52.1, 40.0, 50.8, 37.6, 33.2, 28…
## $ `2000` <dbl> 36.8, 30.2, 33.1, 40.0, 51.8, 40.0, 51.7, 36.2, 33.3, 28…
## $ `2001` <dbl> 36.8, 30.7, 32.6, 40.0, 51.3, 40.0, 51.7, 35.0, 33.4, 29…
## $ `2002` <dbl> 36.8, 31.0, 32.2, 40.0, 50.6, 40.0, 51.4, 35.3, 33.5, 29…
## $ `2003` <dbl> 36.8, 31.1, 31.7, 40.0, 49.7, 40.0, 50.8, 35.3, 33.7, 29…
## $ `2004` <dbl> 36.8, 31.0, 31.2, 40.0, 48.5, 40.0, 49.4, 34.2, 34.0, 29…
## $ `2005` <dbl> 36.8, 30.7, 30.8, 40.0, 47.3, 40.0, 47.9, 33.5, 34.3, 29…
## $ `2006` <dbl> 36.8, 30.4, 30.3, 40.0, 46.2, 40.0, 46.7, 32.7, 34.7, 29…
## $ `2007` <dbl> 36.8, 30.2, 29.9, 40.0, 45.0, 40.0, 45.8, 30.8, 34.9, 30…
## $ `2008` <dbl> 36.8, 30.0, 29.4, 40.0, 44.1, 40.0, 44.9, 29.6, 35.0, 30…
## $ `2009` <dbl> 36.8, 29.7, 29.0, 40.0, 43.4, 40.0, 44.0, 29.6, 34.2, 30…
## $ `2010` <dbl> 36.8, 29.5, 28.5, 40.0, 42.9, 40.0, 43.0, 29.2, 33.6, 30…
## $ `2011` <dbl> 36.8, 29.3, 28.2, 40.0, 42.7, 40.0, 42.3, 29.5, 32.9, 30…
## $ `2012` <dbl> 36.8, 29.1, 27.9, 40.0, 42.6, 40.0, 41.8, 30.2, 32.4, 30…
## $ `2013` <dbl> 36.8, 29.0, 27.7, 40.0, 42.6, 40.0, 41.6, 30.7, 31.9, 30…
## $ `2014` <dbl> 36.8, 29.0, 27.6, 40.0, 42.6, 40.0, 41.6, 31.3, 32.2, 30…
## $ `2015` <dbl> 36.8, 29.0, 27.6, 40.0, 42.6, 40.0, 41.8, 31.9, 32.3, 30…
## $ `2016` <dbl> 36.8, 29.0, 27.6, 40.0, 42.6, 40.0, 42.1, 32.3, 32.3, 30…
## $ `2017` <dbl> 36.8, 29.0, 27.6, 40.0, 42.6, 40.0, 42.3, 32.5, 32.3, 30…
## $ `2018` <dbl> 36.8, 29.0, 27.6, 40.0, 42.6, 40.0, 42.4, 32.6, 32.3, 30…
## $ `2019` <dbl> 36.8, 29.0, 27.6, 40.0, 42.6, 40.0, 42.4, 32.6, 32.3, 30…
## $ `2020` <dbl> 36.8, 29.0, 27.6, 40.0, 42.6, 40.0, 42.4, 32.6, 32.3, 30…
## $ `2021` <dbl> 36.8, 29.0, 27.6, 40.0, 42.6, 40.0, 42.4, 32.6, 32.3, 30…
## $ `2022` <dbl> 36.8, 29.0, 27.6, 40.0, 42.6, 40.0, 42.4, 32.6, 32.3, 30…
## $ `2023` <dbl> 36.8, 29.0, 27.6, 40.0, 42.6, 40.0, 42.4, 32.6, 32.3, 30…
## $ `2024` <dbl> 36.8, 29.0, 27.6, 40.0, 42.6, 40.0, 42.4, 32.6, 32.3, 30…
## $ `2025` <dbl> 36.8, 29.0, 27.6, 40.0, 42.6, 40.0, 42.4, 32.6, 32.3, 30…
## $ `2026` <dbl> 36.8, 29.0, 27.6, 40.0, 42.6, 40.0, 42.4, 32.6, 32.3, 30…
## $ `2027` <dbl> 36.8, 29.0, 27.6, 40.0, 42.6, 40.0, 42.4, 32.6, 32.3, 30…
## $ `2028` <dbl> 36.8, 29.0, 27.6, 40.0, 42.6, 40.0, 42.4, 32.6, 32.3, 30…
## $ `2029` <dbl> 36.8, 29.0, 27.6, 40.0, 42.6, 40.0, 42.4, 32.6, 32.3, 30…
## $ `2030` <dbl> 36.8, 29.0, 27.6, 40.0, 42.6, 40.0, 42.4, 32.6, 32.3, 30…
## $ `2031` <dbl> 36.8, 29.0, 27.6, 40.0, 42.6, 40.0, 42.4, 32.6, 32.3, 30…
## $ `2032` <dbl> 36.8, 29.0, 27.6, 40.0, 42.6, 40.0, 42.4, 32.6, 32.3, 30…
## $ `2033` <dbl> 36.8, 29.0, 27.6, 40.0, 42.6, 40.0, 42.4, 32.6, 32.3, 30…
## $ `2034` <dbl> 36.8, 29.0, 27.6, 40.0, 42.6, 40.0, 42.4, 32.6, 32.3, 30…
## $ `2035` <dbl> 36.8, 29.0, 27.6, 40.0, 42.6, 40.0, 42.4, 32.6, 32.3, 30…
## $ `2036` <dbl> 36.8, 29.0, 27.6, 40.0, 42.6, 40.0, 42.4, 32.6, 32.3, 30…
## $ `2037` <dbl> 36.8, 29.0, 27.6, 40.0, 42.6, 40.0, 42.4, 32.6, 32.3, 30…
## $ `2038` <dbl> 36.8, 29.0, 27.6, 40.0, 42.6, 40.0, 42.4, 32.6, 32.3, 30…
## $ `2039` <dbl> 36.8, 29.0, 27.6, 40.0, 42.6, 40.0, 42.4, 32.6, 32.3, 30…
## $ `2040` <dbl> 36.8, 29.0, 27.6, 40.0, 42.6, 40.0, 42.4, 32.6, 32.3, 30…
income_inequality_clean <- income_inequality %>%
gather(key='year', value='inequality', "1880":"2020") %>%
filter(year > 2005)%>%
select(country, year,inequality) %>%
mutate(year=as.double(year)) %>%
inner_join(happiness_clean, by=c("country"="country_name", "year"="year"))
#glimpse(income_inequality_clean)
#data full
full_data <- income_inequality_clean %>%
inner_join(PPP_clean, by=c("country"="country_name", 'year'='year')) %>%
inner_join(PPPP_clean, by=c("country"="country_name", 'year'='year')) %>%
select(-country_code.x) %>%
inner_join(counrty_region_clean, by=c("country_code.y"="country_code"))
glimpse(full_data)
## Observations: 1,403
## Variables: 19
## $ country <chr> "Armenia", "Austria", "Azerbai…
## $ year <dbl> 2006, 2006, 2006, 2006, 2006, …
## $ inequality <dbl> 32.7, 29.8, 31.9, 33.0, 28.0, …
## $ life_ladder <dbl> 4.289311, 7.122211, 4.727871, …
## $ log_gdp_per_capita <dbl> 8.717719, 10.657212, 9.279043,…
## $ social_support <dbl> 0.6818768, 0.9363504, 0.854414…
## $ healthy_life_expectancy_at_birth <dbl> 64.80, 70.76, 61.88, 59.02, 61…
## $ freedom_to_make_life_choices <dbl> 0.5201978, 0.9413823, 0.771528…
## $ generosity <dbl> -0.216674119, 0.300667107, -0.…
## $ perceptions_of_corruption <dbl> 0.8495131, 0.4901112, 0.774117…
## $ positive_affect <dbl> 0.4941210, 0.8231047, 0.511687…
## $ negative_affect <dbl> 0.4694188, 0.1738117, 0.275695…
## $ confidence_in_national_government <dbl> 0.3443375, 0.4970378, 0.754706…
## $ democratic_quality <dbl> -0.50248164, 1.22430921, -1.18…
## $ ppp <dbl> 1.600727e+02, 8.609180e-01, 2.…
## $ country_code.y <chr> "ARM", "AUT", "AZE", "BGD", "B…
## $ pppp <dbl> 149.7049751, 0.8785690, 0.2253…
## $ region <chr> "Europe & Central Asia", "Euro…
## $ income_group <chr> "Upper middle income", "High i…
# IMPORTING MY DATA
suicide <- read_csv(here::here('data_raw',"newdata3.csv"))
income_per_person <- read_csv(here::here('data_raw',"income_per_person.csv"))
WH_2019 <- read_csv(here::here('data_raw',"WH_2019.csv"))
WH_2018 <- read_csv(here::here('data_raw',"WH_2018.csv"))
WH_2017 <- read_csv(here::here('data_raw',"WH_2017.csv"))
WH_2016 <- read_csv(here::here('data_raw',"WH_2016.csv"))
WH_2015 <- read_csv(here::here('data_raw',"WH_2015.csv"))
#glimpse(WH_2019)
# CLEANING THE WH DATA AND GETTING THE SCORES
#################################################################
WH2019 <- WH_2019 %>%
janitor::clean_names() %>%
mutate(year = 2019) %>%
rename(
rank = overall_rank,
life_ladder = score,
log_gdp_per_capita = gdp_per_capita,
healthy_life_expectancy_at_birth = healthy_life_expectancy,
country = country_or_region) %>%
select(-rank)
#glimpse(WH2019)
# JOIN THE WH DATA TO THE HAPPINESS DATA
adjusted_full <- full_data %>%
full_join(WH2019)
#glimpse(adjusted_full)
# FILTER THE INCOME DATA
#################################################################
income <- income_per_person %>%
gather(key = "year", value = "income_per_person", -country) %>%
mutate(year = as.double(year)) %>%
filter(year %in% c(2015, 2016, 2017, 2018, 2019))
#glimpse(income)
# full join this to djuated data by year and country
WH_Income <- adjusted_full %>%
full_join(income, by = c("country", "year"))
#glimpse(WH_Income)
# FILTER SUICIDE DATA TO JUST HAVE COUNTRY YEAR, SUICIDE RATE
suicide_rates <- suicide %>%
gather(key = "year", value = "suicide_rate", -country, -sex) %>%
mutate(year = as.double(year)) %>%
filter(sex == "Both sexes") %>%
select(-sex)
#glimpse(suicide_rates)
# JOIN TO THE ADJUSTED DATA SET
final_data <- WH_Income %>%
full_join(suicide_rates, by = c("country", "year"))
final_data <- final_data%>%
rename(
'lifeExpAtBirth' = 'healthy_life_expectancy_at_birth',
'freedom' = 'freedom_to_make_life_choices',
'trustInGov' = 'confidence_in_national_government',
'demoQuality' = 'democratic_quality',
'incomePperson' = 'income_per_person',
'suicideR' = 'suicide_rate',
'perceptionCorrupt' = 'perceptions_of_corruption'
)
map_data <- final_data%>%
filter(year == 2019)%>%
select(life_ladder, region=country)%>%
spread(key = region, value = life_ladder)%>%
rename('USA' = 'United States')%>%
gather(key= 'region', value = 'life_ladder', Afghanistan:Zimbabwe)
glimpse(final_data)
## Observations: 2,421
## Variables: 21
## $ country <chr> "Armenia", "Austria", "Azerbaijan", "Banglade…
## $ year <dbl> 2006, 2006, 2006, 2006, 2006, 2006, 2006, 200…
## $ inequality <dbl> 32.7, 29.8, 31.9, 33.0, 28.0, 40.2, 55.1, 62.…
## $ life_ladder <dbl> 4.289311, 7.122211, 4.727871, 4.318909, 5.657…
## $ log_gdp_per_capita <dbl> 8.717719, 10.657212, 9.279043, 7.616417, 9.42…
## $ social_support <dbl> 0.6818768, 0.9363504, 0.8544149, 0.6720022, 0…
## $ lifeExpAtBirth <dbl> 64.80, 70.76, 61.88, 59.02, 61.10, 50.10, 59.…
## $ freedom <dbl> 0.5201978, 0.9413823, 0.7715282, 0.6116642, 0…
## $ generosity <dbl> -0.216674119, 0.300667107, -0.253262460, 0.07…
## $ perceptionCorrupt <dbl> 0.8495131, 0.4901112, 0.7741172, 0.7859162, 0…
## $ positive_affect <dbl> 0.4941210, 0.8231047, 0.5116876, 0.5999454, 0…
## $ negative_affect <dbl> 0.4694188, 0.1738117, 0.2756951, 0.3207928, 0…
## $ trustInGov <dbl> 0.3443375, 0.4970378, 0.7547066, 0.6137370, 0…
## $ demoQuality <dbl> -0.50248164, 1.22430921, -1.18666148, -0.9783…
## $ ppp <dbl> 1.600727e+02, 8.609180e-01, 2.211839e-01, 1.7…
## $ country_code.y <chr> "ARM", "AUT", "AZE", "BGD", "BLR", "BEN", "BO…
## $ pppp <dbl> 149.7049751, 0.8785690, 0.2253549, 18.3772035…
## $ region <chr> "Europe & Central Asia", "Europe & Central As…
## $ income_group <chr> "Upper middle income", "High income", "Upper …
## $ incomePperson <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, N…
## $ suicideR <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, N…
The World Happiness Report is a landmark survey of the state of global happiness. The first report was published in 2012 and continues to gain global recognition as governments and organizations increasingly use happiness indicators to better increase the state of their country. Measurements of well-being can be used effectively to assess the progress of nations.
In this report we look into the pursuit of happiness. This ‘pursuit’ has been a vital part of life as we know it. But what really does happiness look like across the globe? The pursuit of happiness may look different person to person, but are there similarites amoungst nations? Can regions increase their happiness score by utilizing specific factors of life?
What economic and social factors have the most significant impact on the overall level of happiness across the globe?
In our research we utilize four very specific sources in order to reflect the most up to date and trusted variables in accordance to happiness.
This data provided original statistics on over 150 countries around the world. The variables included are appended at the end of this report. The happiness scores were developed from the Gallup World Poll. People answered a main life evaluation question that was asked as a Cantril Ladder. Each person was asked on a scale of 0 (worst life) to 10 (best life), how they would rate their living situation right now. Gallup then used weights to make the estimates representative of the country as a whole.
Information in this set was retrieved from the Kaggle dataset, which was taken directly from the World Health Organization (W.H.O.). This information was gathered by the Global Health Observatory data repository. As more recent and revised data is released, the data is updated.
The data source provides information such as country name, year, Gross Domestic Product (GDP), and Income per person for that country. Gapminder is an independent foundation that focuses on the collection of world data. The data is collected in collaboration with universities, The UN, public agencies, and government agencies around the world.
This allowed us to find global statistics on the Purchasing Power Parity (PPP). The data comes straight from the World Bank. The data set provides statistics on the PPP from years 1990 - 2018. These world development indicators are compiled from officially recognized international sources that represent the “most current and accurate global development data available”.It includes national, regional, and global estimates, therefore this data is vaild and can be trusted.
#map graph
#view(world)
world <- map_data('world') %>%
left_join(map_data, by = 'region') %>%
filter(region!="Antarctica")
glimpse(world)
## Observations: 94,680
## Variables: 7
## $ long <dbl> -69.89912, -69.89571, -69.94219, -70.00415, -70.0661…
## $ lat <dbl> 12.45200, 12.42300, 12.43853, 12.50049, 12.54697, 12…
## $ group <dbl> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2…
## $ order <int> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 13, 14, 15, 16, 1…
## $ region <chr> "Aruba", "Aruba", "Aruba", "Aruba", "Aruba", "Aruba"…
## $ subregion <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, …
## $ life_ladder <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 3.203, 3.203…
ggplot(world)+
geom_polygon(aes(x=long, y=lat, group=group,fill=life_ladder))+
scale_fill_viridis(option = "plasma")+
theme_void()+
labs(fill= "happiness",
title= "2019 World Happiness",caption = "source: https://worldhappiness.report/ed/2019/#read")+
theme(plot.caption = element_text(face = 'bold.italic', hjust = 1),
plot.title = element_text(hjust = .5))