How to create interactive plot using R, RStudio, Quandl, dplyr, ggvis and lubridate in Ubuntu 14.04 LTS 64-bit

Posted: 2015/04/19 in Data Science, Ubuntu
Tags: , , , , , , , , ,
# Reproducible research .R script to run in RStudio in Ubuntu 14.04 LTS 64-bit
# Prerequisites to install: 
# https://mark911.wordpress.com/2014/11/06/how-to-install-newest-version-of-r-and-rstudio-in-ubuntu-14-04-lts-using-a-bash-script/
# Further prerequisites to install in R or RStudio:
install.packages(c("Quandl", "dplyr", "ggvis", "lubridate"))
# Data set: 
# https://www.quandl.com/data/ODA/MOZ_PPPSH-Mozambique-Share-of-World-GDP-based-on-PPP
library(Quandl)
library(dplyr)
library(ggvis)
library(lubridate)
data <- Quandl("ODA/MOZ_PPPSH", authcode="FiHHoC-Gnx3CHzr9385J")
str(data)
dplyr::glimpse(data)
head(data)
tail(data)
data$year <- lubridate::year(data$Date)
min_year <- min(data$year)
max_year <- max(data$year)
# source: https://github.com/rstudio/ggvis/blob/master/vignettes/ggvis-basics.Rmd
# source: Data Wrangling Cheat Sheet:
# http://www.rstudio.com/wp-content/uploads/2015/02/data-wrangling-cheatsheet.pdf
# source: http://ggvis.rstudio.com/0.1/quick-examples.html
data %>% 
 ggvis(~Date,~Value) %>% 
 layer_points() %>% 
 layer_model_predictions(model = input_select(
 c("loess" = "loess",
 "lm" = "lm",
 "MASS::rlm" = "MASS::rlm"),
 label = "model")) %>%
 layer_smooths(se = TRUE,
 span = input_slider(min = 0.3, max = 1, value = 0.8, step = 0.1,
 label = "Smoothing span")) %>%
 add_axis("x", title = "Date") %>%
 add_axis("y", title = "Mozambique Share of World GDP based on PPP, %")
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s