# Load required libraries
library(readxl)
library(lubridate)
## 
## Attaching package: 'lubridate'
## The following objects are masked from 'package:base':
## 
##     date, intersect, setdiff, union
library(plotly)
## Loading required package: ggplot2
## 
## 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
# Read the data
Nerf <- read_xlsx("Nerf.xlsx",
                  col_types = c("date","text", "text", "text", "text", "numeric"))

# Calculate summary statistics
mean_value <- mean(Nerf$Data)
median_value <- median(Nerf$Data)
mode_value <- names(table(Nerf$Data)[which.max(table(Nerf$Data))])

# Create an interactive dot plot using plotly
dot_plot <- plot_ly(data = Nerf, x = ~`Data`, y = ~`Dart Type`,
                    type = "scatter", mode = "markers",
                    color = ~`Data`,
                    colors = colorRamp(c("blue", "red")),
                    sizes = c(5, 20),
                    text = ~paste(`Dart Type`, ": ", `Data`),
                    hoverinfo = "text") %>%
  layout(title = " Dart Distance vs. Dart Type",
         xaxis = list(title = "Distance in Feet ", range = c(min(Nerf$Data) - 5, max(Nerf$Data) + 5)),
         yaxis = list(title = "Dart Type"),
         legend = list(
           title = list(text = "Summary Statistics"),
           orientation = "v",
           xanchor = "right",
           yanchor = "middle",
           x = 1.1,
           y = 0.5,
           bgcolor = "rgba(255, 255, 255, 0.5)",
           bordercolor = "black",
           borderwidth = 1,
           itemsizing = "constant",
           itemwidth = 30,
           itemheight = 20
         ),
         annotations = list(
           x = 1.1, y = 0.5,
           text = paste("Mean: ", mean_value, "<br>",
                        "Median: ", median_value, "<br>",
                        "Mode: ", mode_value),
           font = list(color = "black", size = 12),
           showarrow = FALSE,
           xref = "paper",
           yref = "paper",
           xanchor = "left",
           yanchor = "middle",
           align = "left",
           bgcolor = "rgba(255, 255, 255, 0.7)",
           bordercolor = "black",
           borderwidth = 1,
           borderpad = 4,
           opacity = 0.9
         ))

# Display the dot plot
dot_plot