# Setup libraries
knitr::opts_chunk$set(warning = FALSE, message = FALSE)
library(ggplot2)
library(plotly)
## 
## 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(trelliscopejs)
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
# Load the dataset
dominos_data <- read.csv("C:/Users/babik/Desktop/DV_Assignment/dominos_data.csv")

# Ensure 'store_location' and 'time_of_day' are factors
dominos_data$store_location <- as.factor(dominos_data$store_location)
dominos_data$time_of_day <- as.factor(dominos_data$time_of_day)
dominos_data$pizza_type <- as.factor(dominos_data$pizza_type)

Graph 1: Sales by Time of Day across Store Locations

Investigation Statement:

This graph aims to visualize the sales distribution across different times of the day for various store locations. By comparing these distributions, we can identify peak sales periods and how they vary by location.

with(dominos_data, {
  plot(sales ~ time_of_day, col = as.factor(store_location),
       main = "Sales by Time of Day across Store Locations",
       xlab = "Time of Day", ylab = "Sales ($)",
       pch = 19)
  legend("topright", legend = levels(store_location), col = 1:3, pch = 19)
})

Discussion:

The plot of sales by time of day across several Domino’s store locations provides important insights on consumer behavior and business success throughout the day. This graphic helps to identify peak sales times in retailers, which is important for staff scheduling and inventory management. For example, if the plot reveals sales increases during lunch and evening hours, Domino’s may consider deploying more resources to meet higher customer demand. Furthermore, by comparing sales across several locations, the corporation can detect which stores outperform others during key periods, indicating regions where operational techniques can be reproduced or promotional efforts should be increased to enhance sales.

Graph 2: Sales by Pizza Type and Store Location across Different Times of Day

Investigation Statement:

This graph aims to explore how different types of pizza contribute to sales at various times of the day across different store locations. Understanding this can help tailor marketing strategies for specific products during optimal selling times.

library(ggplot2)
ggplot(dominos_data, aes(x = pizza_type, y = sales, fill = store_location)) +
  geom_bar(stat = "identity", position = "dodge") +
  facet_wrap(~time_of_day) +
  labs(title = "Sales by Pizza Type and Store Location across Different Times of Day",
       x = "Pizza Type", y = "Sales ($)")

Discussion:

The bar chart with facets for pizza type, sales, and store location at different times of day is an important tool for learning how product preferences differ not only by place but also by time. This granular breakdown can indicate important trends, such as a preference for certain pizza types at specific times of day, which can be used to guide targeted marketing campaigns and product positioning strategies. For example, if certain pizzas are more popular in the evening at various areas, Domino’s can tailor its advertising and promotional efforts to capitalize on these preferences. Furthermore, the ggplot library’s facet wrap feature visualizes these complexity in a clear and orderly manner, allowing for easier comparison and better strategic planning based on customer purchasing trends.

Graph 3: 3D Scatter Plot of Sales

Investigation Statement:

This graph investigates the relationship between the time of day, type of pizza, and sales volume in a three-dimensional space. It provides a holistic view of how these variables interact.

library(plotly)
plot_ly(data = dominos_data, x = ~time_of_day, y = ~sales, z = ~pizza_type,
        type = "scatter3d", mode = "markers",
        marker = list(size = 10, color = ~store_location, colorscale = 'Viridis')) %>%
  layout(title = "3D Scatter Plot of Sales",
         scene = list(xaxis = list(title = 'Time of Day'),
                      yaxis = list(title = 'Sales'),
                      zaxis = list(title = 'Pizza Type')))

Discussion:

The 3D scatter plot of sales in the Domino’s dataset shows how several factors, including as time of day, kind of pizza, and store location, interact to influence sales. This visualization is especially useful since it enables stakeholders to spot patterns and trends that are not immediately apparent in typical 2D displays. For example, by rotating the view and inspecting the plot from different perspectives, customers can determine which store locations perform best at specific times or with specific sorts of pizza. This capacity to change the perspective aids in the discovery of vital information, such as peak sales periods or product preferences, which are required for making smart inventory and marketing decisions.

Furthermore, using colors and markers to differentiate across store locations in the scatter plot adds an element of immediate visual interpretation, allowing for the quick identification of high-performing stores or successful goods. The interactive aspect of the plot enables for a more in-depth analysis of the data, with stakeholders able to zoom in on specific data points to obtain comprehensive information, assisting in the formulation of targeted measures to increase sales or solve underperformance. The 3D scatter plot is thus useful not only for visual data interpretation, but also as a strategic asset in optimizing corporate operations and increasing consumer satisfaction through targeted offerings and promotions.

Graph 4: Trelliscope Display of Sales by Pizza Type

Investigation Statement:

This Trelliscope display investigates the detailed variations in sales across different pizza types, allowing us to see unique patterns within subsets of the data. By examining sales data segmented by pizza type in a multi-faceted visual format, we can identify specific trends and anomalies that might be obscured in more aggregated data views.

# Load necessary libraries
library(ggplot2)
library(trelliscopejs)

# Prepare your data and ggplot object
gg <- ggplot(dominos_data, aes(x = sales, y = time_of_day)) +
  geom_point()

# Convert ggplot to a Trelliscope display
gg + facet_trelliscope(
    ~ pizza_type,      # Faceting variable
    nrow = 1,
    ncol = 3,
    path = "path_to_store_trelliscope_displays",  
    self_contained = TRUE  
)

Discussion:

With the Trelliscope display, we can view numerous plots at once, each representing a distinct style of pizza, allowing for a thorough comparison analysis of sales data. Finding patterns unique to various pizza varieties is made easier with the help of this style of representation. Certain pizzas, for example, may sell better at particular times of the day or in particular places, which may indicate potential for focused promotions or exclusive deals.

In addition, the interactive features of the Trelliscope enable users to closely examine and zoom in on specific aspects, offering a more detailed comprehension of the data. Actionable insights may result from this, such as the ability to more precisely alter supply levels in accordance with the anticipated demand for each variety of pizza by using previous sales data. We can efficiently fine-tune our sales strategy to improve overall performance and client pleasure by enabling such in-depth analyses.

All things considered, the Trelliscope display is an effective tool for breaking down large, complicated statistics into smaller, easier to understand parts. This helps decision-makers identify and respond to new trends and patterns in their sales data.