---
title: "Data Visualization"
editor: visual
---

```{r echo=FALSE, message=FALSE, warning=FALSE}
library(flipbookr)
library(tidyverse)
library(ggplot2)
library(forecast)
library(astsa) 
library(xts)
library(tseries)
library(fpp2)
library(fma)
library(lubridate)
library(tidyverse)
library(TSstudio)
library(quantmod)
library(tidyquant)
library(plotly)
library(ggplot2)

```

```{r}
options("getSymbols.warning4.0"=FALSE)
options("getSymbols.yahoo.warning"=FALSE)

tickers = c("MSFT","SBUX","COST" )
for (i in tickers){
  getSymbols(i,
             from = "2012-10-01",
             to = "2022-12-01")}

x <- list(
  title = "date"
)
y <- list(
  title = "value"
)

stock <- data.frame(MSFT$MSFT.Adjusted,
                    SBUX$SBUX.Adjusted,
                    COST$COST.Adjusted)


stock <- data.frame(stock,rownames(stock))
colnames(stock) <- append(tickers,'Dates')

stock$date<-as.Date(stock$Dates,"%Y-%m-%d")
head(stock)
```

```{r}
ggplot(stock, aes(x=date)) +
  geom_line(aes(y=MSFT, colour="MSFT"))+
  geom_line(aes(y=SBUX, colour="SBUX"))+
  geom_line(aes(y=COST, colour="COST"))+
   labs(
    title = "Stock Prices for the Top Companies",
    subtitle = "From 2013-2022",
    x = "Date",
    y = "Adjusted Closing Prices")+
    theme(panel.background = element_rect(fill = "white", colour = "grey50"))+
    guides(colour=guide_legend(title="Tech Companies")) 
```

```{r}
g4<- ggplot(stock, aes(x=date)) +
  geom_line(aes(y=MSFT, colour="MSFT"))+
  geom_line(aes(y=SBUX, colour="SBUX"))+
  geom_line(aes(y=COST, colour="COST"))+
   labs(
    title = "Stock Prices for the Top Companies",
    subtitle = "From 2013-2022",
    x = "Date",
    y = "Adjusted Closing Prices")+
    guides(colour=guide_legend(title="Top Companies")) 


ggplotly(g4) %>%
  layout(hovermode = "x")
```
