library(tidyverse)
## Warning: package 'tidyverse' was built under R version 4.6.1
## Warning: package 'ggplot2' was built under R version 4.6.1
## Warning: package 'tibble' was built under R version 4.6.1
## Warning: package 'tidyr' was built under R version 4.6.1
## Warning: package 'readr' was built under R version 4.6.1
## Warning: package 'purrr' was built under R version 4.6.1
## Warning: package 'dplyr' was built under R version 4.6.1
## Warning: package 'stringr' was built under R version 4.6.1
## Warning: package 'forcats' was built under R version 4.6.1
## Warning: package 'lubridate' was built under R version 4.6.1
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.2.1     ✔ readr     2.2.0
## ✔ forcats   1.0.1     ✔ stringr   1.6.0
## ✔ ggplot2   4.0.3     ✔ tibble    3.3.1
## ✔ lubridate 1.9.5     ✔ tidyr     1.3.2
## ✔ purrr     1.2.2     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(plotly)
## Warning: package 'plotly' was built under R version 4.6.1
## 
## Attaching package: 'plotly'
## 
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## 
## The following object is masked from 'package:stats':
## 
##     filter
## 
## The following object is masked from 'package:graphics':
## 
##     layout
library(gganimate)
## Warning: package 'gganimate' was built under R version 4.6.1
library(shiny)
## Warning: package 'shiny' was built under R version 4.6.1
library(DT)
## Warning: package 'DT' was built under R version 4.6.1
## 
## Attaching package: 'DT'
## 
## The following objects are masked from 'package:shiny':
## 
##     dataTableOutput, renderDataTable
superstore <- readxl::read_excel("SuperstoreSales.xlsx")
head(superstore)
## # A tibble: 6 × 23
##   RowID OrderID OrderDate           OrderPriority OrderQuantity   Sales Discount
##   <dbl>   <dbl> <dttm>              <chr>                 <dbl>   <dbl>    <dbl>
## 1     1       3 2010-10-13 00:00:00 Low                       6  262.       0.04
## 2     2       6 2012-02-20 00:00:00 Not Specified             2    6.93     0.01
## 3     3      32 2011-07-15 00:00:00 High                     26 2808.       0.07
## 4     4      32 2011-07-15 00:00:00 High                     24 1761.       0.09
## 5     5      32 2011-07-15 00:00:00 High                     23  160.       0.04
## 6     6      32 2011-07-15 00:00:00 High                     15  141.       0.04
## # ℹ 16 more variables: ShipMode <chr>, Profit <dbl>, UnitPrice <dbl>,
## #   ShippingCost <dbl>, CustomerName <chr>, City <chr>, ZipCode <chr>,
## #   State <chr>, Region <chr>, CustomerSegment <chr>, ProductCategory <chr>,
## #   ProductSubCategory <chr>, ProductName <chr>, ProductContainer <chr>,
## #   ProductBaseMargin <dbl>, ShipDate <dttm>

###This report presents interactive and animated visualizations of Superstore sales data.

Visualization 1: Interactive Bar Chart (Sales by Category)

p1 <- superstore %>%
  group_by(ProductCategory) %>%
  summarise(TotalSales = sum(Sales)) %>%
  plot_ly(x = ~ProductCategory, y = ~TotalSales, type = "bar")
p1

###Visualization 2: Interactive Line Chart (Sales Over Time)

p2 <- superstore %>%
  group_by(OrderDate) %>%
  summarise(DailySales = sum(Sales)) %>%
  plot_ly(x = ~OrderDate, y = ~DailySales, type = "scatter", mode = "lines")
p2

###Visualization 3: Animated Scatter Plot (Sales vs Profit by Region)

p3 <- ggplot(superstore, aes(x = Sales, y = Profit, color = Region)) +
  geom_point() +
  transition_time(OrderDate) +
  labs(title = "Sales vs Profit over Time: {frame_time}")
animate(p3)

####Visualization 4: Interactive Heatmap (Sales by Category & Region)

p4 <- superstore %>%
  group_by(ProductCategory, Region) %>%
  summarise(TotalSales = sum(Sales)) %>%
  plot_ly(x = ~ProductCategory, y = ~Region, z = ~TotalSales, type = "heatmap")
## `summarise()` has regrouped the output.
## ℹ Summaries were computed grouped by ProductCategory and Region.
## ℹ Output is grouped by ProductCategory.
## ℹ Use `summarise(.groups = "drop_last")` to silence this message.
## ℹ Use `summarise(.by = c(ProductCategory, Region))` for per-operation grouping
##   (`?dplyr::dplyr_by`) instead.
p4

####Visualization 5: Interactive Box Plot (Profit Distribution by Segment)

p5 <- plot_ly(superstore, x = ~CustomerSegment, y = ~Profit, type = "box")
p5

####Visualization 6: Animated Line Chart (Cumulative Sales Over Time)

p6 <- superstore %>%
  arrange(OrderDate) %>%
  mutate(CumulativeSales = cumsum(Sales)) %>%
  ggplot(aes(x = OrderDate, y = CumulativeSales)) +
  geom_line(color = "blue") +
  transition_reveal(OrderDate)
animate(p6)

####Visualization 7: Interactive Pie Chart (Sales Share by Ship Mode)

p7 <- superstore %>%
  group_by(ShipMode) %>%
  summarise(TotalSales = sum(Sales)) %>%
  plot_ly(labels = ~ShipMode, values = ~TotalSales, type = "pie")
p7

####Visualization 8: Interactive Dashboard Table (Top 10 Products by Sales)

top_products <- superstore %>%
  group_by(ProductName) %>%
  summarise(TotalSales = sum(Sales)) %>%
  arrange(desc(TotalSales)) %>%
  head(10)

datatable(top_products)