Dashboard

Row

Creating map plot to present country against its’ happiness score.

Happiness Score vs. Various factors affecting it(such as GDP per Capita, Freedom to make life choices and Perceptions of corruption within the government)

Row

Top 10 country Score and Freedom to make life choices

Bottom 10 country score and Freedom to make life choices

Theory

Row

Theory

  • The first plot simply denotes each country’s happiness score index.

  • The second plot, on the other hand, compares the happiness score to various factors affecting it such as the country’s GDP, Freedom to make life choices and the population’s perception of corruption within the country’s government. It can be perceived that GDP doesn’t have much of an effect on the population’s happiness though it has a slight increase in the score, it starts to get static at about 0.8 GDP per capita. However, the freedom to make choices affect the happiness score on a large scale. The plot can be seen to increase linearly, denoting that the population seems to be happier with more freedom. Lastly, the population’s perception of a corrupted government doesn’t seem to have much of an effect on the population’s happiness. Finally, we can conclude that the happiness score depends on the population’s freedom to make life choices the most when compared to the country’s GDP and the population’s perception of corruption within its government.

  • The final two plots graph the top 10 and bottom 10 country’s with regards to their happiness score w.r.t. it’s freedom in making life choices.

References

Row

References

---
title: "World Happiness Report; with reference to economic production, social support, etc. "

output: 
  flexdashboard::flex_dashboard:
    orientation: rows
    source_code: embed
---

```{r setup, include=FALSE}
#installing packages
#installing packages
library('dplyr')
library('stringr')
library('ggplot2')
library('maps')
library('viridis')
library('ggplot2')
library('plotly')
library('sf')
library('tmap')
library('tidyverse')
library('plotly')
library('viridis')
library('hrbrthemes')
library('ggthemes')

options(scipen = 999)

#Preparing data to use for visualisations
setwd("C:/Users/nupur/Desktop/DVA3")
file_df <- read.csv(file = 'worldhappinessreport2019.csv')
str(file_df)

countries <- st_read(dsn = "World_Countries", 
                     layer = "World_Countries")

head(data.frame(countries))

join <- left_join(countries, file_df, by = c("COUNTRY" = "Country.or.region"))
data <- join %>% filter(!is.na(`Score`)) 
head(data.frame(data))

fig3 <- file_df[,c(1,2,3,4,7)]
fig3<- head(fig3, 10)
str(fig3)

fig4 <- file_df[,c(1,2,3,4,7)]
fig4<- tail(fig4, 10)
str(fig4)

```

Dashboard
=======================================================================

Row
-----------------------------------------------------------------------

### Creating map plot to present country against its' happiness score.

```{r}
tmap_mode("plot")

tm_shape(data)+
  tm_fill("Score" ,
          title='World Happiness Index',
          style = "quantile", 
          palette = "RdYlGn")+
  tm_layout(legend.outside = TRUE,
            legend.position = c("right", "bottom"),
            frame = FALSE
  ) +
  tm_borders(alpha = 0.5) +
  tm_compass(type="8star", size = 2) +
  tm_scale_bar(width = 0.15) 


map <- tm_shape(data) +
  tm_polygons("Score",
              title='World Happiness Index',
              style = "quantile", 
              palette = "RdYlGn") +
  tm_layout(legend.height = 0.45, 
            legend.width = 0.3,
            legend.outside = FALSE,
            legend.position = c("right", "bottom"),
            frame = FALSE
  ) +
  tm_borders(alpha = 0.5) 


tmap_mode("view")

map

```

### Happiness Score vs. Various factors affecting it(such as GDP per Capita, Freedom to make life choices and Perceptions of corruption within the government)

```{r}
fig2 <- plot_ly(file_df) %>%
  
  add_markers(x = ~`GDP.per.capita`,y = ~Score,name = "Score vs. GDP", text =
                ~paste("Country:", `Country.or.region`, 'Happiness Rank:', `Overall.rank`)) %>%
  
  add_markers(x =~`Freedom.to.make.life.choices`,y = ~Score , name = "Avg yrs of schooling vs. CPI", text =
                ~paste("Country:", `Country.or.region`, 'Happiness Rank:', `Overall.rank`), visible =FALSE) %>%
  
  
  add_markers(x = ~`Perceptions.of.corruption`, name ="GDP per capita vs Score",y = ~Score, text =
                ~paste("Country:", `Country.or.region`,'Happiness Rank:', `Overall.rank`), visible = FALSE) %>%
  
  
  layout(
    title = "Happiness Score vs. Various factors affecting it",
    xaxis = list( title ="GDP Per Capita", range=c(0.3,1)),
    yaxis = list(title = "Happiness Score"),
    
    showlegend = FALSE,
    
    updatemenus = list(
      list(
        y = 1, x = -0.1,
        buttons = list(
          list(method = "update",
               args = list(list(visible = list(T, F, F)),
                           list(xaxis = list(title = "GDP Per Capita", range=c(0.3,1)))),
               label = "GDP" ),
          
          list(method = "update",
               args = list(list(visible = list(F, T, F)),
                           list(xaxis = list(title = "Freedom to make life choices"))),
               label = "Freedom"),
          
          list(method = "update",
               args = list(list(visible = list(F, F, T)),
                           list(xaxis = list(title = "Perceptions of corruption"))),
               label = "POC")
        ))
    )
  )

fig2
```

Row
-----------------------------------------------------------------------

### Top 10 country Score and Freedom to make life choices


```{r}
fig3 <- plot_ly(fig3, x = ~Country.or.region, y = ~Freedom.to.make.life.choices, type = 'bar', name = 'Freedom to make life choices')
fig3 <- fig3 %>% add_trace(y = ~Score, name = 'Score')
fig3 <- fig3 %>% layout(yaxis = list(title = 'Count'), barmode = 'stack', title = 'Top 10 Happiest Countries Compared to Freedom to.make life choices')

fig3
```

### Bottom 10 country score and Freedom to make life choices

```{r}
fig4 <- plot_ly(fig4, x = ~Country.or.region, y = ~Freedom.to.make.life.choices, type = 'bar', name = 'Freedom to make life choices')
fig4 <- fig4 %>% add_trace(y = ~Score, name = 'Score')
fig4 <- fig4 %>% layout(yaxis = list(title = 'Count'), barmode = 'stack', title = 'Least Happy Countries Compared to Freedom to make life choices')

fig4

```

Theory
=======================================================================

Row
-----------------------------------------------------------------------

### Theory

* The first plot simply denotes each country's happiness score index. 

* The second plot, on the other hand, compares the happiness score to various factors affecting it such as the country's GDP, Freedom to make life choices and the population's perception of corruption within the country's government. It can be perceived that GDP doesn't have much of an effect on the population's happiness though it has a slight increase in the score, it starts to get static at about 0.8 GDP per capita. However, the freedom to make choices affect the happiness score on a large scale. The plot can be seen to increase linearly, denoting that the population seems to be happier with more freedom. Lastly, the population's perception of a corrupted government doesn't seem to have much of an effect on the population's happiness. Finally, we can conclude that the happiness score depends on the population's freedom to make life choices the most when compared to the country's GDP and the population's perception of corruption within its government.

* The final two plots graph the top 10 and bottom 10 country's with regards to their happiness score w.r.t. it's freedom in making life choices.

References
=======================================================================

Row
-----------------------------------------------------------------------

### References

* 2019 - World Happiness Report. Retrieved 5 June 2022, from https://www.kaggle.com/datasets/unsdsn/world-happiness?select=2019.csv.
* Carlos Efraín Porto Tapiquén, World Shapefiles (*.shp), viewed 8 June 2023, .