In February 2017, the United Arab Emirates held a full-day World Happiness meeting, as part of the World Government Summit. Now on World Happiness Day, March 20th, we launch the World Happiness Report 2017, once again back at the United Nations, again published by the Sustainable Development Solutions Network, and now supported by a generous three-year grant from the Ernesto Illy Foundation.

Load the file

head(happy_2017)

Descriptive Statistics

Quantiles plot

ggplot(data = happy_2017,aes(x="Region",y=Freedom))+geom_boxplot(aes(fill=Region))

Variance and Standard Deviation

var(happy_2017$Happiness.Score)
## [1] 1.246317
sqrt(var(happy_2017$Happiness.Score))
## [1] 1.116386
sd(happy_2017$Happiness.Score)
## [1] 1.116386

Summary Statistics

library(knitr)
kable(summary(happy_2017))
Country Region Happiness.Rank Happiness.Score Economy..GDP.per.Capita. Family Health..Life.Expectancy. Freedom Generosity Trust..Government.Corruption. Dystopia.Residual
Afghanistan: 1 Sub-Saharan Africa :36 Min. : 1.00 Min. :2.905 Min. :0.02264 Min. :0.3961 Min. :0.005565 Min. :0.0000 Min. :0.0000 Min. :0.00000 Min. :0.3779
Albania : 1 Central and Eastern Europe :29 1st Qu.: 39.25 1st Qu.:4.519 1st Qu.:0.71891 1st Qu.:1.0494 1st Qu.:0.398654 1st Qu.:0.3022 1st Qu.:0.1523 1st Qu.:0.05717 1st Qu.:1.6016
Algeria : 1 Latin America and Caribbean :22 Median : 77.50 Median :5.286 Median :1.06695 Median :1.2548 Median :0.609627 Median :0.4389 Median :0.2312 Median :0.08957 Median :1.8298
Angola : 1 Western Europe :21 Mean : 77.19 Mean :5.380 Mean :0.99260 Mean :1.1971 Mean :0.557302 Mean :0.4091 Mean :0.2458 Mean :0.12247 Mean :1.8550
Argentina : 1 Middle East and Northern Africa:19 3rd Qu.:115.75 3rd Qu.:6.103 3rd Qu.:1.31503 3rd Qu.:1.4190 3rd Qu.:0.717596 3rd Qu.:0.5199 3rd Qu.:0.3240 3rd Qu.:0.15264 3rd Qu.:2.1477
Armenia : 1 Southeastern Asia : 8 Max. :154.00 Max. :7.537 Max. :1.87077 Max. :1.6106 Max. :0.949492 Max. :0.6582 Max. :0.8381 Max. :0.46431 Max. :3.1175
(Other) :144 (Other) :15 NA NA NA NA NA NA NA NA NA

Histogram

g<-ggplot(data=happy_2017,aes(Freedom))
g+geom_histogram(bins = 15)

Density Plot

g+geom_density()

Correlation

##correlation
kable(cor(happy_2017[4:11]))
Happiness.Score Economy..GDP.per.Capita. Family Health..Life.Expectancy. Freedom Generosity Trust..Government.Corruption. Dystopia.Residual
Happiness.Score 1.0000000 0.8080129 0.7476163 0.7783037 0.5784059 0.1603838 0.4422911 0.5066391
Economy..GDP.per.Capita. 0.8080129 1.0000000 0.6751627 0.8316497 0.3757427 -0.0232999 0.3561506 0.0593484
Family 0.7476163 0.6751627 1.0000000 0.6023747 0.4337487 0.0652770 0.2360538 0.1001615
Health..Life.Expectancy. 0.7783037 0.8316497 0.6023747 1.0000000 0.3597246 0.0568294 0.2826280 0.0928880
Freedom 0.5784059 0.3757427 0.4337487 0.3597246 1.0000000 0.3154470 0.4950476 0.0942454
Generosity 0.1603838 -0.0232999 0.0652770 0.0568294 0.3154470 1.0000000 0.2882775 -0.1128735
Trust..Government.Corruption. 0.4422911 0.3561506 0.2360538 0.2826280 0.4950476 0.2882775 1.0000000 0.0058970
Dystopia.Residual 0.5066391 0.0593484 0.1001615 0.0928880 0.0942454 -0.1128735 0.0058970 1.0000000

Correlation Plot

#install.packages("corrplot")

library(corrplot)
corrplot(cor(happy_2017[4:11]))

plot(happy_2017[4:11])

Analysis and Visualization

attach(happy_2017)
table(Region)
## Region
##       Australia and New Zealand      Central and Eastern Europe 
##                               2                              29 
##                    Eastern Asia     Latin America and Caribbean 
##                               4                              22 
## Middle East and Northern Africa                   North America 
##                              19                               2 
##               Southeastern Asia                   Southern Asia 
##                               8                               7 
##              Sub-Saharan Africa                  Western Europe 
##                              36                              21
Regions <- table(Region) %>% as.data.frame()
ggplot(data=Regions,aes(Region,Freq))+geom_col(aes(fill= Region))+ggtitle("No of Country from Different Region")+coord_flip()

head(arrange(happy_2017,desc(Happiness.Rank)),10)

Top 10 Happiest countries

top_10<- head(arrange(happy_2017,Happiness.Rank),10)
top_10$Country<- as.factor(top_10$Country)

top_10
ggplot(top_10, aes(x = reorder(Country,-Happiness.Score), y = Happiness.Score, fill = Country)) +
  geom_bar(stat = "identity") +
  labs(title = "Top 10 World's Happiest Countries")+ theme(axis.text.x = element_text(angle = 90))

Unhappy_country <- head(arrange(happy_2017,desc(Happiness.Rank)),10)
Unhappy_country
ggplot(Unhappy_country,aes(x=reorder(Country,Happiness.Score), y=Economy..GDP.per.Capita.,fill=Country))+geom_bar(stat = "Identity")+labs(title="GDP Per capita of Unhappy country",x="Country Name",y="Gdp Per Capita")+coord_flip()

poor_country<-head(arrange(happy_2017,Economy..GDP.per.Capita.),10)
ggplot(poor_country,aes(x=reorder(Country,Economy..GDP.per.Capita.),y=Freedom))+geom_bar(stat = "identity",aes(fill=Country))+labs(title="Freedom in Poor country")+theme_minimal()+theme(legend.position="",axis.text.x=element_text(angle=90, hjust=1))

#Most corrupt country 
corrupt_country<-head(arrange(happy_2017,Trust..Government.Corruption.),10)
ggplot(corrupt_country,aes(x=reorder(Country,Trust..Government.Corruption.),y=Trust..Government.Corruption.,fill=Country))+geom_bar(stat = "Identity")+theme_minimal()+theme(legend.position="",axis.text.x=element_text(angle=90, hjust=1))+labs(x="Country Name",y="Trust or Corruption")

Analysis of SAARC Region

#happy_2017[happy_2017$Region=="Southern Asia",]
saarc <- happy_2017%>% filter(Region=="Southern Asia")
saarc$Country <- as.character(saarc$Country)
cat("Poor Country in Saarc:",saarc$Country[which.min(saarc$Economy..GDP.per.Capita.)])
## Poor Country in Saarc: Afghanistan
cat("\nRich Country in Saarc:",saarc$Country[which.max(saarc$Economy..GDP.per.Capita.)])
## 
## Rich Country in Saarc: Sri Lanka
ggplot(saarc,aes(x=reorder(Country,Economy..GDP.per.Capita.),y=Economy..GDP.per.Capita.,fill=Country))+geom_col()+labs(title="Gdp per capita of SAARC Country",x="",y="GDP Per Capita")+theme_minimal()+theme(legend.position = "")

head(saarc)
ggplot(arrange(saarc,Health..Life.Expectancy.),aes(x=reorder(Country,Health..Life.Expectancy.),y=Health..Life.Expectancy.,fill=Country))+ geom_col()+labs(title="Life Expectancy in SAARC Country",x="",y="Life Expectancy")+theme_minimal()+theme(legend.position = "")

ggplot(arrange(saarc,Trust..Government.Corruption.),aes(x=reorder(Country,Trust..Government.Corruption.),y=Trust..Government.Corruption.,fill=Country))+ geom_col()+labs(title="Trust for Government in SAARC Country",x="",y="Trust")+theme_minimal()+theme(legend.position = "")

ggplot(arrange(saarc,Generosity),aes(x=reorder(Country,Generosity),y=Generosity,fill=Country))+ geom_col()+labs(title="Generosity in SAARC Country",x="",y="Generosity")+theme_minimal()+theme(legend.position = "")

ggplot(arrange(saarc,Freedom),aes(x=reorder(Country,Freedom),y=Freedom,fill=Country))+ geom_col()+labs(title="Freedom in SAARC Country",x="",y="Freedom")+theme_minimal()+theme(legend.position = "")

ggplot(arrange(saarc,Happiness.Score),aes(x=reorder(Country,Happiness.Score),y=Happiness.Score,fill=Country))+ geom_col()+labs(title="Happiness in SAARC Country",x="",y="Happiness Score")+theme_minimal()+theme(legend.position = "")

ggplot(arrange(saarc,Happiness.Rank),aes(x=reorder(Country,Happiness.Rank),y=Happiness.Rank,fill=Country))+ geom_col()+labs(title="Happiness Rank in SAARC Country",x="",y="Happiness Rank")+theme_minimal()+theme(legend.position = "")+geom_text(aes(label = round(Happiness.Rank, 2)), position = position_stack(vjust = 0.5), size = 3)