library(readr)
library(dplyr)
library(tidyverse)
library(reactable)
For this assignment, I thought I would revisit the dataset I used for our last assignment. However, instead of using just the happiness score, I wanted
This data set was published by the World Happiness Report and downloaded from kaggle. It uses information from the Gallup World Survey and bases scores off several different factors and the degree to which they contribute to the countryโs happiness.
Description for columns gathered from:
Helliwell, J. F., Layard, R., Sachs, J. D., De Neve, J.-E., Aknin, L. B., & Wang, S. (Eds.). (2022). World Happiness Report 2022. New York: Sustainable Development Solutions Network. https://happiness-report.s3.amazonaws.com/2022/WHR+22.pdf, page 21.
happiness <- read_csv("2022happinessReport.csv",
col_types = cols(`Dystopia (1.83) + residual` = col_number(),
`Explained by: GDP per capita` = col_number(),
`Explained by: Social support` = col_number(),
`Explained by: Healthy life expectancy` = col_number(),
`Explained by: Freedom to make life choices` = col_number(),
`Explained by: Generosity` = col_number(),
`Explained by: Perceptions of corruption` = col_number()))
Many of the predictors were calculated as the result of the answers to a poll question. The related question is listed below.
tbl_happy <- happiness %>%
# select columns for table
select(RANK, Country, `Happiness score`,`Explained by: GDP per capita`,
`Explained by: Social support`,
`Explained by: Healthy life expectancy`,
`Explained by: Freedom to make life choices`,
`Explained by: Generosity`,
`Explained by: Perceptions of corruption`) %>%
reactable(
# make default settings for all columns
defaultColDef = colDef(
headerStyle = list(fontWeight = 750),
align = "center",
format = colFormat(separators = TRUE)
),
# customize column names
columns = list(
RANK = colDef(name = "Ranking", align = "center"),
`Explained by: GDP per capita`= colDef(name="GDP per capita"),
`Explained by: Social support`= colDef(name = "Social Support"),
`Explained by: Healthy life expectancy`=
colDef(name = "Healthy Life Expectancy"),
`Explained by: Freedom to make life choices` =
colDef(name = "Freedom to make life choices"),
`Explained by: Generosity`= colDef(name = "Generosity"),
`Explained by: Perceptions of corruption` =
colDef(name = "Perceptions of Corruption")
),
columnGroups = list(
colGroup(name = "Explained by",columns=c("Explained by: GDP per capita",
"Explained by: Social support",
"Explained by: Healthy life expectancy",
"Explained by: Freedom to make life choices",
"Explained by: Generosity",
"Explained by: Perceptions of corruption"))),
searchable = TRUE,
showPageSizeOptions = TRUE,
striped = TRUE,
style = list(fontSize = "1rem"),
defaultSorted = "RANK")
tbl_happy