This Project is to create interactive plot to analyze Google’s branch stock index from 2015 to the most recent date of 2017 (2017-04-17). The historical Google stock index data can be found from here in Google Finance.
library(plyr)
library(plotly)
setwd("F:/google")
google_manipulation <- function(file, col_name) {
data <- read.csv(file, stringsAsFactors = FALSE)[, c(1,5)]
names(data) <- c("date", col_name)
data$date <- as.Date(data$date, format = "%d-%b-%y")
return(data)
}
credit_card <- google_manipulation("crcard.csv", "credit_card")
education <- google_manipulation("educat.csv", "education")
financial_planning <- google_manipulation("finpln.csv", "financial_planning")
insurance <- google_manipulation("insur.csv", "insurance")
small_business <- google_manipulation("smallbiz.csv", "small_business")
google <- join_all(list(credit_card, education, financial_planning, insurance, small_business),
by = "date")
dim(google)
google_15to17 <- subset(google, subset = google$date >= "2015-01-01")
dim(google_15to17)
Â
A Time Series Plot of Google Stock Index are made with two features:
Basic Range Slider to select the range of date by moving the slider;
Selector Buttons to selct the data within 3 months, 6 months, 1 year or year to date (YTD).
p <- plot_ly(google_15to17, x = ~date) %>%
add_lines(y = ~credit_card, name = "Credit Card") %>%
add_lines(y = ~education, name = "Education") %>%
add_lines(y = ~financial_planning, name = "Financial Planning") %>%
add_lines(y = ~insurance, name = "Insurance") %>%
add_lines(y = ~small_business, name = "Small Business") %>%
layout(
title = "Google Stock Index",
xaxis = list(
rangeselector = list(
buttons = list(
list(
count = 3,
label = "3 mo",
step = "month",
stepmode = "backward"),
list(
count = 6,
label = "6 mo",
step = "month",
stepmode = "backward"),
list(
count = 1,
label = "1 yr",
step = "year",
stepmode = "backward"),
list(
count = 1,
label = "YTD",
step = "year",
stepmode = "todate"),
list(step = "all"))),
rangeslider = list(type = "date")),
yaxis = list(title = "Stock Index"))
p