Introduction

You will use this code as a template for your Visualization 3 assignment. The first step is to call a set of packages that you might use in this assignment. The final choices belong to you.

Note that each code chunk is set off with special tags.

library(ggplot2)
library(dplyr)
library(ggvis)
library(WDI)
library(plotly)
library(maps)
library(ggmap)

world <- map_data("world") # set up world map

Call package WDI to retrieve most updated figures available.

In this assignent, we need to update 8 series:

Tableau Name WDI Series
Birth Rate SP.DYN.CBRT.IN
Health Exp % GDP SH.XPD.TOTL.ZS
Health Exp/Capita SH.XPD.PCAP
Infant Mortality Rate SP.DYN.IMRT.IN
Internet Usage IT.NET.USER.ZS
Life Expectancy (Total) SP.DYN.LE00.IN
Mobile Phone Usage IT.CEL.SETS.P2
Population Total SP.POP.TOTL

The next code chunk will call the WDI API and fetch the years 2000 through 2016, as available. It will then remove the country regional and other aggregates.

birth <- "SP.DYN.CBRT.IN"
hxpgdp <- "SH.XPD.TOTL.ZS"
hxpcap <- "SH.XPD.PCAP"
infmort <- "SP.DYN.IMRT.IN"
net <-"IT.NET.USER.ZS"
lifeexp <- "SP.DYN.LE00.IN"
mobile <- "IT.CEL.SETS.P2"
pop <- "SP.POP.TOTL"

# create a vector of the desired indicator series
indicators <- c(birth, hxpgdp, hxpcap, infmort, net, lifeexp, mobile, pop)

newdata <- WDI(country="all", indicator = indicators, 
     start = 2000, end = 2016, extra = TRUE)

# remove country groupings
newdata$longitude[newdata$longitude==""] <- NA
countries <- filter(newdata, !is.na(longitude))  # drop aggregate groups
## Warning: package 'bindrcpp' was built under R version 3.4.2
## rename columns for each of reference
countries <- rename(countries, birth = SP.DYN.CBRT.IN, 
       hxpgdp = SH.XPD.TOTL.ZS, hxpcap = SH.XPD.PCAP, 
       infmort = SP.DYN.IMRT.IN, net  = IT.NET.USER.ZS,
       lifeexp = SP.DYN.LE00.IN, mobile = IT.CEL.SETS.P2, 
       pop = SP.POP.TOTL)

glimpse(countries) ## data frame column names appear here
## Observations: 3,485
## Variables: 18
## $ iso2c     <chr> "AD", "AD", "AD", "AD", "AD", "AD", "AD", "AD", "AD"...
## $ country   <chr> "Andorra", "Andorra", "Andorra", "Andorra", "Andorra...
## $ year      <dbl> 2013, 2006, 2015, 2004, 2005, 2007, 2003, 2008, 2009...
## $ birth     <dbl> NA, 10.600, NA, 10.900, 10.700, 10.100, 10.300, 10.4...
## $ hxpgdp    <dbl> 11.478046, 5.313893, NA, 5.703882, 5.223353, 6.33545...
## $ hxpcap    <dbl> 4914.3912, 2256.1030, NA, 2127.7367, 2089.6678, 2997...
## $ infmort   <dbl> 2.7, 3.3, 2.5, 3.5, 3.3, 3.2, 3.6, 3.1, 3.0, 2.9, 2....
## $ net       <dbl> 94.00000, 48.93685, 96.91000, 26.83795, 37.60577, 70...
## $ lifeexp   <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, ...
## $ mobile    <dbl> 80.70262, 84.27764, 88.12353, 73.82494, 79.48487, 78...
## $ pop       <dbl> 80788, 80991, 78014, 76244, 78867, 82683, 73182, 838...
## $ iso3c     <fctr> AND, AND, AND, AND, AND, AND, AND, AND, AND, AND, A...
## $ region    <fctr> Europe & Central Asia (all income levels), Europe &...
## $ capital   <fctr> Andorra la Vella, Andorra la Vella, Andorra la Vell...
## $ longitude <fctr> 1.5218, 1.5218, 1.5218, 1.5218, 1.5218, 1.5218, 1.5...
## $ latitude  <fctr> 42.5075, 42.5075, 42.5075, 42.5075, 42.5075, 42.507...
## $ income    <fctr> High income: nonOECD, High income: nonOECD, High in...
## $ lending   <fctr> Not classified, Not classified, Not classified, Not...

Population Health Indicators graph (Graph 1)

## Your plotting code goes here
library(ggplot2)
ggplot(countries, aes(as.factor(year), lifeexp, group = region, col = region)) + geom_bin2d() + theme_classic() + theme(axis.line=element_blank(),
      axis.ticks=element_blank(),
      axis.title.x=element_text(),
      axis.title.y=element_text(),
      legend.position="none",
      panel.background=element_blank(),
      panel.border=element_blank(),
      panel.grid.major=element_blank(),
      panel.grid.minor=element_blank(),
      plot.background=element_blank()) +
  xlab("Years(2000 - 2016)") +
  ylab("Life Expectency Frequency") + 
  ggtitle("Time Series of Average Life Expectancy, Colored by Region")

Care Spending 2015 (Graph 2)

library(ggplot2)
ggplot(countries, aes(as.factor(year), hxpcap, col = region, alpha = hxpgdp)) + geom_point() + geom_jitter() + theme_classic() + coord_flip() + xlab("Health Exp as % of GDP Per Capita") + ylab("Years") + labs(title = "Health Exp. of the World", subtitle = "Colored by Region, Opacity by GDP")
## Warning: Removed 682 rows containing missing values (geom_point).

## Warning: Removed 682 rows containing missing values (geom_point).

Technology graph (Graph 3)

This is Health Expenditure of the world as a percent of GDP. In order to fit all of the countries I decided to use a scatter plot. Although it is not interactive, we can still still see the increase of health care expenditure over the years. It is interesting to see how the different countries in the same region behave alike. It appears that countries in Europe and North America spend the most percent of their income on health expenditure.

## Your plotting code goes here
library(ggplot2)
ggplot(countries, aes(as.factor(year), net)) + geom_boxplot(col = "red", outlier.colour = "orange", outlier.shape = 5, outlier.alpha = .8, fill = "green") + geom_smooth() + xlab("Years(2000-2016)") + ylab("Internet Usage of All Countries") +theme_classic() +ggtitle("Boxplot of Internet Usage by Year")
## `geom_smooth()` using method = 'loess'

It is clear that the world has continued its trend of hyperconnectivety. The percent of mobile users has steadied out, and the percent of internet users has increased. There are some outliers depicted as orange diamonds, yet they disapear as the world becomes better connected to the internet. # Conclusion

Overall, in every regard, (Life Expectancy, Mobile/Net usage, percent of Health Expenditure by GDP) the world has been improving and is continuing to improve. Although my graphs are not duplicates of the Tableau’s World Indicator graphs, they show how the world has improved since 2012.