Higher national income (as measured by GDP per capita) is generally associated with higher life expectancy at birth
Max Roser, Esteban Ortiz-Ospina and Hannah Ritchie (2013) - “Life Expectancy”. Published online at OurWorldInData.org. Retrieved from: ‘https://ourworldindata.org/life-expectancy’ [Online Resource]
Life expectancy by country and in the world (2021). (n.d.). Worldometer - real time world statistics. https://www.worldometers.info/demographics/life-expectancy/
flex_dashboard: R Markdown Format for Flexible Dashboards (Created on July 8, 2020, 7:32 p.m) https://rdrr.io/cran/flexdashboard/man/flex_dashboard.html
Line Plots in R (2021) Graphing Libraries https://plotly.com/r/line-charts/#style-line-plots
DataTables changing font size in R DataTables (DT): https://www.py4u.net/discuss/876925
Axes in R (2021) Graphing Libraries https://plotly.com/r/axes/#set-axis-title-font
Engel, C. A. (n.d.). Chapter 2 interactive graphs | Data visualization with R. Page not found · GitHub Pages. https://cengel.github.io/R-data-viz/interactive-graphs.html
---
title: "Life Expectancy"
output:
flexdashboard::flex_dashboard:
orientation: rows
source_code: embed
---
```{r setup, include=FALSE}
library(flexdashboard)
library(ggplot2)
library(maps)
library(magrittr)
library(dplyr)
library(tidyverse)
library(ggiraph)
library(widgetframe)
library(ggthemes)
library(plotly)
library(viridis)
library(DT)
library(scales)
library(plotly)
library(gapminder)
# setwd("Desktop/Y3/DV/A3")
Plot1 <- read.csv("life-expectancy.csv")
Fig2 <-read.csv("life-expectancy-cont.csv")
Fig3 <-read.csv("Fig3.csv")
Fig4 <-read.csv("fig4.csv")
Fig5 <-read.csv("life-gdp.csv")
```
## R Markdown
Overview
=======================================================================
Row
-----------------------------------------------------------------------
### Life expectancy across the world (Countries)
```{r}
Plot1 = filter(Plot1, Year=="2015")
fig1 <- plot_ly(Plot1, locations = ~Code, z = ~LifeExpectancy,
type='choropleth', color = ~LifeExpectancy, colors = 'Blues',
text = ~paste("Country:", `Entity`,
'Life Expectancy Year:', `Year`,
'Life Expectancy', `LifeExpectancy`))
fig1 <- fig1 %>% colorbar(title = 'LifeExpectancy Scale', x =-0, y =1)
fig1 <- fig1 %>% layout(title = 'Life Expectancy 2015',
height = 400, margin = list(t = 40),
geo = list(showframe = FALSE, showcoastlines = FALSE))
fig1
```
### Today, most people in the world can expect to live as long as those in the very richest countries in 1950. The United Nations estimate a global average life expectancy of 72.6 years for 2015 – the global average today is higher than in any country back in 1950.
```{r}
Fig2$Entity <- factor(Fig2$Entity,levels = Fig2$Entity[order(Fig2$LifeExpectancy)])
p <- ggplot(data=Fig2, aes(x=Entity, y=LifeExpectancy)) + geom_bar(stat="identity",color = "#FFFFFF", fill = "deepskyblue3") +
geom_text(aes(y = LifeExpectancy + 2 * sign(LifeExpectancy), label =LifeExpectancy,hjust=0.2), position = position_dodge(width = 0), size = 2.5, angle = 360)+ labs(title = "Life Expectancy Around the World",x = "", y = "Life Expectancy (In Years)")+
theme_minimal()+coord_flip()
p
```
Row
-----------------------------------------------------------------------
### Top 10 Countries who have the highest happiness score between 2015-2019
```{r}
t10happy<- plot_ly(Fig3) %>%
add_lines(x = ~Year, y = ~HS, group = ~Country,
color = ~Country) %>%
layout( title = "Trend of Top 10 most happiest countries in the world",
yaxis = list(zeroline = FALSE, title = "Happiness Score", range = c(5, 10)),
xaxis = list(zeroline = FALSE, title = "Year"))
t10happy
```
### Top 10 countries with the highest life expectancy in 2015
```{r}
Fig4$male <- as.numeric(as.character(Fig4$male))
Fig4$female <- as.numeric(as.character(Fig4$female))
Fig4$total <- as.numeric(as.character(Fig4$total))
Fig4 <- Fig4 %>% gather(`male`,`female`,`total`,key='Gender',value='Value')
p1<- ggplot(Fig4, aes(fill=`Gender`, y=Value, x=`Entity`)) +
geom_bar( width = 0.7,stat="identity",position="dodge")+
labs(x = "", y = "Life Expectancy in years", fill = "Gender")+
scale_fill_manual(values = c("#8ecae6","#219ebc", "#023047"))+
coord_flip()+
labs(x = "Country") +
geom_text( aes( label = paste0(" ",Value ), y = Value ),
position = position_dodge(width = 1), hjust = 0,size = 2.5,color = "black")+
theme_minimal()+
theme(text = element_text(size=10)) +
theme(axis.text.x = element_text(angle = 0))+
theme(legend.position="right")
p1
```
Life Exp vs GDP
=======================================================================
Row
-----------------------------------------------------------------------
### Representation of various indicators with Life Expectancy such as GDP per capita in 2015
Higher national income (as measured by GDP per capita) is generally associated with higher life expectancy at birth
```{r}
Fig5 = filter(Fig5, Year=="2015")
Fig5 <- plot_ly(data = Fig5, x = ~GDP, y = ~LifeExpectancy)%>% layout(title = 'Life Expectancy vs GDP per capita', xaxis = list(title = 'GDP per capita'), yaxis = list(title = 'Life Expectancy'), plot_bgcolor = "#e5ecf6")
Fig5
```
Row
-----------------------------------------------------------------------
References
=======================================================================
1. Max Roser, Esteban Ortiz-Ospina and Hannah Ritchie (2013) - "Life Expectancy". Published online at OurWorldInData.org. Retrieved from: 'https://ourworldindata.org/life-expectancy' [Online Resource]
2. Life expectancy by country and in the world (2021). (n.d.). Worldometer - real time world statistics. https://www.worldometers.info/demographics/life-expectancy/
3. flex_dashboard: R Markdown Format for Flexible Dashboards (Created on July 8, 2020, 7:32 p.m) https://rdrr.io/cran/flexdashboard/man/flex_dashboard.html
4. Line Plots in R (2021) Graphing Libraries https://plotly.com/r/line-charts/#style-line-plots
5. DataTables changing font size in R DataTables (DT): https://www.py4u.net/discuss/876925
6. Axes in R (2021) Graphing Libraries https://plotly.com/r/axes/#set-axis-title-font
7. Engel, C. A. (n.d.). Chapter 2 interactive graphs | Data visualization with R. Page not found · GitHub Pages. https://cengel.github.io/R-data-viz/interactive-graphs.html