Created
December 29, 2011 04:04
-
-
Save christophergandrud/1531789 to your computer and use it in GitHub Desktop.
Japan US gdp change comparison graph
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############################## | |
# Create a Google Line Graph to Compare the Difference between Japanese & US GDP Growth using Data | |
# from the World Bank | |
# Christopher Gandrud | |
# Updated 29 December 2011 | |
############################## | |
library(WDI) | |
library(gregmisc) | |
library(googleVis) | |
## Get data from World Bank | |
# Japan | |
gdp <- WDI(country = c("jp"), indicator = c("NY.GDP.MKTP.KD.ZG"), start = 1980, end = 2010) | |
gdp <- rename.vars(gdp, from = "NY.GDP.MKTP.KD.ZG", to = "japan.annual", info = FALSE) | |
japan.percapita <- WDI(country = c("jp"), indicator = c("NY.GDP.PCAP.KD.ZG"), start = 1980, end = 2010) | |
gdp <- gdp[,3:4] | |
japan.percapita <- japan.percapita[,4] | |
# US | |
us.annual <- WDI(country = c("us"), indicator = c("NY.GDP.MKTP.KD.ZG"), start = 1980, end = 2010) | |
us.percapita <- WDI(country = c("us"), indicator = c("NY.GDP.PCAP.KD.ZG"), start = 1980, end = 2010) | |
us.annual <- us.annual[,4] | |
us.percapita <- us.percapita[,4] | |
## Combine data | |
gdp <- cbind(gdp, japan.percapita, us.annual, us.percapita) | |
## Create difference in annual GDP % Change (Japan - US) | |
gdp$Overall <- gdp$japan.annual - gdp$us.annual | |
## Create difference in annual per capita GDP % Change (Japan - US) | |
gdp$PerCapita <- gdp$japan.percapita - gdp$us.percapita | |
## Make googleVis plots | |
gdp.comparison <- gvisLineChart(gdp, xvar = "year", yvar = c("Overall", "PerCapita"), options = list( | |
title ="Japanese GDP Growth Compared to the US", | |
vAxis = "{title:'Difference of Japanese & US GDP % Change', baselineColor:'orange'}" | |
)) | |
plot(gdp.comparison) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment