---
title: "DASHBOARD"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
source_code: embed
---
```{r message = FALSE}
library("flexdashboard")
library("tidyquant")
```
```{r message = FALSE}
symbols <- c("MSFT","AAPL","TWTR")
data <- tq_get(symbols)
invisible(data %>%
select(symbol, date, close) %>%
spread(key = symbol, value = close))
data$day <- weekdays(as.Date(data$date,'%Y-%m-%d'))
data$weekNum <- strftime(data$date, format = "%V")
library("lubridate")
data$month <- month(as.POSIXlt(data$date, format="%Y/%m/%d"))
data$difference = data$close - data$open
```
```{r message = FALSE}
library(ggplot2)
library(xts)
```
```{r message = FALSE}
msft <- data[data$symbol == "MSFT",]
aapl <-data[data$symbol == "AAPL",]
twtr <- data[data$symbol == "TWTR",]
```
Column {.tabset data-width=300}
-----------------------------------------------------------------------
### Stock Closing Prices
```{r message = FALSE}
ggplot(msft,aes(date,close)) +
geom_line(aes(color="msft")) +
geom_line(data=aapl,aes(color="aapl")) +
geom_line(data=twtr,aes(color="twtr")) +
labs(color="Legend") +
scale_colour_manual("test", breaks = c("msft", "aapl","twtr"),
values = c("blue", "yellow","red")) +
ggtitle("Closing Stock Prices: MSFT, AAPL & TWTR") +
theme(plot.title = element_text(lineheight=.7, face="bold"))
```
```{r message = FALSE}
msft_xts <- xts(msft$close,order.by=msft$date,frequency=365)
aapl_xts <- xts(aapl$close,order.by=aapl$date,frequency=365)
twtr_xts <- xts(twtr$close,order.by=twtr$date,frequency=365)
stocks <- cbind(aapl_xts,twtr_xts,msft_xts)
```
### Stock Closing Prices Interactive
```{r}
library(dygraphs)
dygraph(stocks,ylab="Close",
main="Closing Stock Prices") %>%
dySeries("..1",label="AAPL") %>%
dySeries("..2",label="TWTR") %>%
dySeries("..3",label="MSFT") %>%
dyOptions(colors = c("blue","brown","green")) %>%
dyRangeSelector()
```
```{r message = FALSE}
start <- as.Date("2014-09-01")
end <- as.Date("2017-09-01")
```
Column {.tabset-fade .tabset data-width=300}
-------------------------------------
### AAPL
```{r}
invisible(getSymbols("AAPL", src = "yahoo", from = start, to = end))
candleChart(AAPL, up.col = "black", dn.col = "red", theme = "white")
```
### TWTR
```{r}
invisible(getSymbols("TWTR", src = "yahoo", from = start, to = end))
candleChart(TWTR, up.col = "black", dn.col = "red", theme = "white")
```
### MSFT
```{r message = FALSE}
invisible(getSymbols("MSFT", src = "yahoo", from = start, to = end))
candleChart(MSFT, up.col = "black", dn.col = "red", theme = "white")
```
Column {data-width=300}
-------------------------------------
### Stock Closing Price Dotted
```{r message = FALSE}
invisible(stocks <- as.xts(data.frame(AAPL = AAPL[, "AAPL.Close"],
MSFT = MSFT[, "MSFT.Close"],
TWTR = TWTR[, "TWTR.Close"]
)))
```
```{r message = FALSE}
plot(as.zoo(stocks), screens = 1, lty = 1:3, xlab = "Date", ylab = "Price")
legend("right", c("AAPL", "MSFT", "TWTR"), lty = 1:3, cex = 0.5)
```