Problem 1

library(trelliscopejs)
library(tidyverse)
library(ggplot2)
library(dslabs)
library(dplyr)
library(plotly)
plot_ly(x = ~iris$Sepal.Length,y = ~iris$Sepal.Width, color = ~iris$Species,text = ~paste("Species: ", iris$Species, "\nSepal Length: ", iris$Sepal.Length, "\nSepal Width: ", iris$Sepal.Width)) %>%
  layout(xaxis = list(title = "Sepal Length"),
         yaxis = list(title = "Sepal Width"),
         title = "Sepal Width VS Sepal Length by Species",
         paper_bgcolor = "lightgray",
         plot_bgcolor = "lightgray")

The scatter plot displays the relationship between Sepal Length and Sepal Width across different species. By hovering over the graphing elements, it’s easy to discern the specific counts of Sepal Length and Sepal Width for each species.

Problem 2

data <-readRDS("C://Users/ROG/Desktop/Stocks/nsdq2016.rds")
data_ungroup <- ungroup(data)
view(data_ungroup)
plot_animation <- data_ungroup %>%
  filter(symbol %in% c("QQQ","FB","TLT", "AAPL")) %>%
  filter(month(date) == 1) %>%
  mutate(date = as.Date(date, format = "%Y-%m-%d")) %>%
  mutate(Trade_Date = as.character(date)) %>%
  plot_ly(x=~volume ,y=~close, color = ~symbol,size = 3,text =  ~paste("Volume: ", volume,"\nClose Price:",close))%>%
  add_markers(frame = ~Trade_Date)

plot_animation %>%
  add_text(x = 70000000, y =110 ,text = ~Trade_Date,frame = ~Trade_Date,textfont = list(color = "lightgray"),showlegend = FALSE) %>%
  animation_slider(currentvalue = TRUE) %>%
  animation_opts(frame = 2000,transition = 1000,
                 easing = "sin") %>%
  layout(xaxis = list(title  = "Trading Volume"),
         yaxis = list(title = "Closing Price"),
         title = "Volume VS Closing in 2016 January")

The dynamic Plotly graph depicts the fluctuation of close prices alongside changes in trading volume for Apple, Facebook, the Exchange-traded Fund, and the iShares 20+ Year Treasury Bond ETF in January 2016. It’s evident that price movements correlate with shifts in trading volume. Apple experienced a significant drop in close price amidst high trading volume on On Jan -27, attributed to reports highlighting the escalating legal dispute between Apple and the FBI regarding access to an iPhone linked to the 2015 San Bernardino attack. Conversely, Facebook’s close price and trading volume surged following the release of its financial results for Q4 and full-year 2015 on Jan-28.