Skip to content

Instantly share code, notes, and snippets.

@CliffordAnderson
Last active August 29, 2015 14:17
Show Gist options
  • Save CliffordAnderson/a25ffb263892fca8d577 to your computer and use it in GitHub Desktop.
Save CliffordAnderson/a25ffb263892fca8d577 to your computer and use it in GitHub Desktop.
Compare the annual GDP growth in China and the United States
# Load libraries
library(ggplot2)
library(Quandl)
# Load datasets from Quandl
USA <- Quandl("WORLDBANK/USA_NY_GDP_MKTP_KD_ZG", authcode="[TOKEN")
China <- Quandl("WORLDBANK/CHN_NY_GDP_MKTP_KD_ZG", authcode="[TOKEN")
# Merge datasets into single table
Comp <- China
Comp$USA <- USA$Value
names(Comp)[2] <- "China"
# Build line plot
plot <- ggplot(Comp, aes(x=Date))
plot <- plot + geom_line(aes(y = USA), color="red")
plot <- plot + geom_line(aes(y = China), color="blue")
plot <- plot + xlab(label="Year")
plot <- plot + ylab(label="Annual GDP Growth")
plot <- plot + ggtitle("Comparison Annual GDP Growth in USA and China")
# Display plot
plot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment