The world is a rapidly changing place. Among the fastest changing aspects are those relating to how people communicate and interact with each other. The World Happiness Report is a landmark survey of the state of global happiness that ranks over 150 countries by how happy citizens perceive themselves to be. In this visualisation, we will be utilizing some powerful packages in R such as ggplot2 to visualize the extend of the impact of GDP per capita, life expectancy, generosity and freedom to make life choices on countries’ happiness scores in 2019.
Challenges faced prior to constructing the visualization are:
Given the four factors shown above, the first challenge was to decide whether to include many factors using bubble chart of varying bubble size or to showcase the relationship between happiness score and each of the four factors respectively into 4 separate charts then combining them in one visualization.
Second challenge involves adding the interactivity element in the visualization as initially I was unfamiliar of any library with the interactive visualization capability.
Another challenge was to decide that provided interactivity issue is resolved, what will be the information shown as the hover text to present to the audience the most informative insight.
These challenges were later resolved upon drafting and additional research done, as a consequence, a sketch design is presented below to address the aforementioned challenges.
▪ ggplot2 is used primarily for graph building as it is a system for declaratively creating graphics, based on The Grammar of Graphics
▪ plotly is an R graphing library makes interactive, publication-quality graphs.
packages = c('ggplot2','plotly')
for (p in packages){
if(!require(p,character.only = T)){
install.packages(p)
}
library(p,character.only = T)
}
In this visualization we will only be using the 2019 happiness score. Therefore upon data import we will subset the data to use the happiness scores for 2019 only. An important point to emphasize about the data set is that the data for the four factors used here are in the form of the extent to which a particular factor affect the happiness score of a country. FOr example, the data used here for GDP per capita is not the actual amount of GDP per capita for each country, rather the extent to which GDP contributes to the calculation of the Happiness Score. For more details of how the data is derived, please visit https://worldhappiness.report.
# import data for world happiness index from 2015-2019
df <- read.csv('happiness.csv')
# for visualisation purpose we subset the 2019 set of data
d19 <- df %>%
select(Overall.rank,Country,Country,Region,Score,GDP.per.capita,Healthy.life.expectancy,Freedom.to.make.life.choices,Generosity,Year) %>%
filter(Year == 2019)
To construct the visualisation proposed in the sketch design, we first construct one of the four plots–Happiness against GDP per capita for the countries. Once this plot has been done, the remaining 3 plots will follow a similar skeleton with specific changes to distinguish among the four.
Scatter plot is plotted using plotly’s interactive capability to visualize the interaction between each of the four chosen factors and countries’ happiness.
In this chart although all the data points are of the same size (this was done to ensure the plot only communicate the relationship between happiness and the chosen factor), they vary in color intensity as those data points of higher color intensity represents the countries with a higher Happiness Score in 2019.
We first use ggplot2 to construct the basic plots for each of the factors. We then apply plotly’s ggplotly function to add the interactivity layer to the visualization.
With plotly library’s interactivity, upon hovering cursor over any data point, the specific country name, the region where the country belongs to, the specific Happiness Score and the country’s global Happiness rank in 2019 can be viewed as a tooltip.
The code below shows the specific visualization:
#________________________________________________GDP_____________________________________________________
pgdp<- ggplot(d19, aes(x=GDP.per.capita, y=Score,color=Score,
text = paste("Country: ", Country,
"<br>Region: ", Region,
"<br>Happiness Score", Score,
"<br>Global rank: ", Overall.rank))) +
geom_point()+
theme_bw()+
theme(legend.position = "none")+ #remove colout legend
scale_color_gradient(low="light green", high="dark green")+
labs(y = "Happiness Score",
x = "GDP per capita")+
theme(axis.title.x = element_text(face="bold",family = "Arial", color="dark green", size=10),
axis.title.y = element_text(family = "Arial", color="grey", size=10))
pgdp <- ggplotly(pgdp, tooltip = "text")
#__________________________________LIFE EXPECTANCY__________________________________________
#constructing the chart for happiness score against extent to which life expectancy associate with happiness
pexp<- ggplot(d19, aes(x=Healthy.life.expectancy, y=Score,color=Score,
text = paste("Country: ", Country,
"<br>Region: ", Region,
"<br>Happiness Score", Score,
"<br>Global rank: ", Overall.rank))) +
geom_point()+
theme_bw()+
theme(legend.position = "none")+ #remove colour legend
scale_color_gradient(low="lightsalmon1", high="darkorange4")+
labs(y = "Happiness Score",
x = "Life Expectancy")+
theme(axis.title.x = element_text(face="bold",family = "Arial", color="orange", size=10),
axis.title.y = element_text(family = "Arial", color="grey", size=10))
pexp<- ggplotly(pexp, tooltip = "text")
#________________________________GENEROSITY______________________________________________
#constructing the chart for happiness score against extent to which generosity associate with happiness
pgen<- ggplot(d19, aes(x=Generosity, y=Score,color=Score,
text = paste("Country: ", Country,
"<br>Region: ", Region,
"<br>Happiness Score", Score,
"<br>Global rank: ", Overall.rank))) +
geom_point()+
theme_bw()+
theme(legend.position = "none")+ #remove colour legend
scale_color_gradient(low="lightblue2", high="navyblue")+
labs(y = "Happiness Score",
x = "Generosity")+
theme(axis.title.x = element_text(face="bold",family = "Arial", color="blue", size=10),
axis.title.y = element_text(family = "Arial", color="grey", size=10))
pgen<- ggplotly(pgen, tooltip = "text")
#__________________________Freedom.to.make.life.choices___________________________________________
#constructing the chart for happiness score against extent to which freedom to make life choices associate with happiness
pfree<- ggplot(d19, aes(x=Freedom.to.make.life.choices, y=Score,color=Score,
text = paste("Country: ", Country,
"<br>Region: ", Region,
"<br>Happiness Score", Score,
"<br>Global rank: ", Overall.rank))) +
geom_point()+
theme_bw()+
theme(legend.position = "none")+ #remove colour legend
scale_color_gradient(low="lightgray", high="grey40")+
labs(y = "Happiness Score",
x = "Freedom to make life choices")+
theme(axis.title.x = element_text(face="bold",family = "Arial", color="grey20", size=10),
axis.title.y = element_text(family = "Arial", color="grey", size=10))
pfree <- ggplotly(pfree, tooltip = "text")
The final visualisation is constructed by using the subplot function to merge the four plotly graphs into a single object in a single view. Furthermore, the chart title is added with specified formats to summarise one of the key findings of the visualisation.
fig <- subplot(pgdp,pexp, pgen, pfree, nrows = 2,titleX =TRUE,titleY = TRUE,shareX = FALSE,margin = 0.12) %>%
layout(title="GDP and life expectancy appear to have strongrer positive correlation with Happiness Scores ",
titlefont = list(
family = "Arial black",
size =13,
color = 'black'))
fig
Given the visualisation aims to visualise the relationship between country’s Happiness Score and the impact of a particular factor have on the score, this visualisation simply answers the question:
“To what extent are factors such as GDP,life expectancy,generosity and freedom to make life choices associated with happiness?”
It is common to think that economic development as measured by GDP per capita affects citizens happiness. This can be seen in the visualisation that in the plot for GDP per capita, we observe a general positive relationship between GDP and Happiness Score, denoting that in general countries with high GDP per capita tend to have happier citizens. However, economic advancement doesn’t seem to be the only factor affecting people’s happiness. We observe a generally higher Happiness Score in countries where there’s a higher focus on life expectancy. A similarly positive relationship is observed in the visualisation for freedom to make life choices as we see that citizens tend to be happier with more emphasis on freedom to make life decisions.
In the case of generosity, however, citizens from countries with the highest Happiness Scores (such as Finland and Norway) do not necessarily put generosity as a high regard as the less ‘happier’ citizens in Myanmar perceive.
Therefore, from what we can observe from this visualisation, we can conclude that economic factor (as denoted by GDP per capita), health condition (as illustrated by life expectancy) and the degree of control citizens have over their own personal life (as shown by freedom to make life choices) seem to be more positively associated with people’s happiness around the globe.