2025-11-02

Introduction & Welcome

World Happiness & Inflation

  • Dataset: WHI_Inflation.csv (World Happiness metrics + inflation indicators)
  • Our goal here is to explore the relationships visually between inflation and happiness across countries and continents
  • Tools used: ggplot2, plotly, linear regression, ioslides (presentation)

Data & Source

There are 17 Columns:

  • Among Happiness: Score, GDP per Capita, Social support, Healthy life expectancy at birth, Freedom to make life choices, Generosity, Perceptions of corruption

  • Among Inflation: Headline Consumer Price Inflation, Food Consumer Price Inflation, Energy Consumer Price Inflation, Official Core Consumer Price Inflation, Producer Price Inflation, GDP deflator Index growth rate

  • Keys: Country, Year, Continent

Brief Project Overview

We are going to go through the World Happiness & Inflation data set and explore what it has to offer through different visualizations to help us better understand the data.

We will see:

  • ggplot: Distribution of Happiness by Continent
  • ggplot: Correlations between Happiness and Life Factors
  • plotly: Happiness vs. Levels of Inflation
  • plotly: Happiness Trends Over Time by Continent
  • 3D plotly: Freedom, GDP vs. Happiness

And finally,

  • statistical analysis: Linear Regression

Data Snapshot

The top 6 entries from the data set for viewers’ information:

Country Continent Year Score GDP per Capita Headline Consumer Price Inflation
Afghanistan Asia 2015 3.5750 0.3198200 -0.660
Afghanistan Asia 2016 3.3600 0.3822700 4.380
Afghanistan Asia 2017 3.7940 0.4014772 4.976
Afghanistan Asia 2018 3.6320 0.3320000 0.630
Afghanistan Asia 2019 3.2030 0.3500000 2.302
Afghanistan Asia 2020 2.5669 0.3007058 5.443

Code Example: Violin Plot

Below is the R code used to make the violin plot from the dataset.

n_labs=as.data.frame(table(whi$Continent)) #plot labels
names(n_labs)=c("Continent","n") #number of countries
whi2=merge(whi, n_labs, by="Continent")
whi2$label=paste0(whi2$Continent, " (n = ", whi2$n, ")")

ggplot(whi2, aes(x = label, y = Score, fill = Continent)) +
  geom_violin(trim = FALSE, alpha = 0.7) + #violin shape
  geom_boxplot(width = 0.1, color = "white", alpha = 0.5) + #box
  labs(title = "Happiness by Continent (number of countries shown)", 
       x = "Continent", y = "Happiness Score") + #title + axis label
  theme_minimal() + theme(legend.position = "none") #no legend
  #colors are intuitive

ggplot: Happiness by Continent

Happiness levels vary. Europe, South America, Oceania, and North America tend to have higher median scores, while Africa and Asia have lower. South America has minimal variability. Oceania sits highest and is widest, meaning that its few countries have consistently high, similar happiness scores. Height means more variability, while width shows density.

Code Example: Correlation Heat Map

Below is the R code used to make the heat map.
library(reshape2) #below are all the variable names
num_data=whi[, c("Score", "GDP per Capita", "Social support",
                    "Healthy life expectancy at birth",
                    "Freedom to make life choices", "Generosity",
                    "Perceptions of corruption",
                    "Headline Consumer Price Inflation")]
cor_matrix=round(cor(num_data, use = "complete.obs"), 2)
melted=melt(cor_matrix)
ggplot(melted,aes(Var1, Var2, fill = value)) +
  geom_tile(color="white")+
  scale_fill_gradient2(low="#d73027",high="#1a9850", #range
                       mid="white",midpoint=0,limit=c(-1, 1)) +
  labs(title = "Correlations of Happiness and Life Factors",
       x = "", y = "", fill = "Correlation") + #titles and axes
  theme_minimal(base_size = 14) +
theme(axis.text.x=element_text(angle = 45, hjust = 1, size = 10),
      axis.text.y=element_text(size=10)) #adjusting squares

ggplot: What Drives Happiness?

Happiness has positive relationships with GDP, social support, life expectancy, and freedom. Wealthier and freer societies are happier. Inflation and corruption lower happiness slightly. Here, green means two things rise together, so when GDP goes up, so does happiness, and vise versa.

plotly: Happiness vs. Levels of Inflation

Oceania shows the greatest happiness, even under high inflation. Africa and Asia are less, suggesting that economic pressure affects happiness more here. Inflation groups were divided into thirds (0.33%). There are different countries in each group, categorized based on their inflation level during the year.

Code Example: Line Graph

Below is the R code used to make the line graph.
pline=plot_ly( #trend over time by continent line graph
  by_continent_year,
  x =~Year, #x and y variables
  y =~mean_score,
  color=~Continent, 
  customdata=~Continent,   
  type="scatter", #graph details
  mode ="lines+markers",
  hovertemplate = paste(
    "Year: %{x}<br>", #interactive details
    "Continent: %{customdata}<br>",  
    "Mean Score: %{y:.2f}<extra></extra>"
  )) %>%layout( #title and axes labels
    title = "Average Happiness Score Over Time by Continent",
    xaxis = list(title = "Year"),
    yaxis = list(title = "Mean Happiness Score"))
pline

plotly: Trend Over Time by Continent

Happiness scores have remained stable. Oceania shows the highest happiness, while Africa has the lowest. Europe and North America show gradual increases over time, suggesting economic and social stability. Asia and South America have flat or declining trends.

3D plotly: Freedom, GDP vs. Happiness

Countries with both high GDP and freedom have the highest happiness, shown by the clusters toward the top of the graph. Oceania, Europe, and North America dominate this area, while Africa and Asia show lower GDP and freedom, correlating with lower happiness. The plot suggests that economic stability and freedom together influences happiness.

Statistics: Linear Regression

## 
## Call:
## lm(formula = Score ~ `Headline Consumer Price Inflation` + `GDP per Capita`, 
##     data = whi)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -3.2785 -0.8233  0.0233  0.8218  2.9196 
## 
## Coefficients:
##                                      Estimate Std. Error t value Pr(>|t|)    
## (Intercept)                          5.415642   0.042443 127.599  < 2e-16 ***
## `Headline Consumer Price Inflation` -0.009081   0.001266  -7.174 1.31e-12 ***
## `GDP per Capita`                     0.056124   0.009199   6.101 1.44e-09 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.102 on 1142 degrees of freedom
## Multiple R-squared:  0.07107,    Adjusted R-squared:  0.06944 
## F-statistic: 43.69 on 2 and 1142 DF,  p-value: < 2.2e-16
  • β₁ (Headline CPI): Correlation between inflation + happiness (negative = higher inflation, lower happiness).
  • β₂ (GDP per Capita): Higher income correlates with higher happiness.
  • p-values and R² for significance

Statistical Analysis

We looked at how inflation and income correlate to people’s happiness.

  • The model shows a significant relationship between the economic factors and happiness (p < 0.001).

  • Inflation = –0.0091: Negatively associated with happiness. So, as inflation rises, happiness decreases.

  • GDP per Capita = 0.0561: Positively associated. So, higher income means greater happiness.

The results show that countries with higher GDP per person tend to have higher happiness, while higher inflation is linked to a lower happiness. This suggests that economic stability and wealth/income both play an important role in how happy people are across different continents.

Conclusion

After analyses, we found that happiness is shaped by economic and social factors. Wealthier continents, like Oceania and North America, consistently saw higher happiness, even during times of increasing inflation, while areas with lower income and less freedom tend to score lower. Our correlation/regression results show that higher GDP and freedom are strong positive influences on happiness, while inflation and corruption reduce it.

Although money and stability matters, the data infers that happiness is not driven just by economics, as social support, health, and freedom play important roles, as well. These findings show that a good economy helps, but real happiness depends on balance of financial security, well-being, and personal freedom.

Goodbye!

Thank you for your time.