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(tidyverse)
library(ggvis)
library(WDI)
library(plotly)
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
## 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...
## Your plotting code goes here
## Your plotting code goes here
## Your plotting code goes here
## Your plotting code goes here
** write a sentence or two summarizing noteworthy changes in recent years.