Load Data

df <- read_csv("WHR_15_23.csv")
## Rows: 1367 Columns: 9
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): country, region
## dbl (7): happiness_score, gdp_per_capita, generosity, social_support, freedo...
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
glimpse(df)
## Rows: 1,367
## Columns: 9
## $ country                      <chr> "Switzerland", "Iceland", "Denmark", "Nor…
## $ region                       <chr> "Western Europe", "Western Europe", "West…
## $ happiness_score              <dbl> 7.587, 7.561, 7.527, 7.522, 7.427, 7.406,…
## $ gdp_per_capita               <dbl> 1.39651, 1.30232, 1.32548, 1.45900, 1.326…
## $ generosity                   <dbl> 0.29678, 0.43630, 0.34139, 0.34699, 0.458…
## $ social_support               <dbl> 1.34951, 1.40223, 1.36058, 1.33095, 1.322…
## $ freedom_to_make_life_choices <dbl> 0.66557, 0.62877, 0.64938, 0.66973, 0.632…
## $ healthy_life_expectancy      <dbl> 0.94143, 0.94784, 0.87464, 0.88521, 0.905…
## $ year                         <dbl> 2015, 2015, 2015, 2015, 2015, 2015, 2015,…

Convert Country to Factor for Filtering

df <- df %>%
mutate(country = as.factor(country))

Freedom Plot

freedom_plot <- plot_ly(
data = df,
x = ~year,
y = ~freedom_to_make_life_choices,
color = ~country,
type = 'scatter',
mode = 'lines+markers',
hoverinfo = 'text',
text = ~paste("Country:", country,
"Year:", year,
"Freedom:", round(freedom_to_make_life_choices, 2))
) %>%
layout(
title = "Freedom to Make Life Choices Over Time",
xaxis = list(title = "Year"),
yaxis = list(title = "Freedom to Make Life Choices", range = c(0, 1))
)

freedom_plot
## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors

## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors

Social Support

social_plot <- plot_ly(
data = df,
x = ~year,
y = ~social_support,
color = ~country,
type = 'scatter',
mode = 'lines+markers',
hoverinfo = 'text',
text = ~paste("Country:", country,
"Year:", year,
"Social Support:", round(social_support, 2))
) %>%
layout(
title = "Social Support Over Time",
xaxis = list(title = "Year"),
yaxis = list(title = "Social Support", range = c(0, 2))
)

social_plot
## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors

## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors