# 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","guess",
                                "guess","guess",
                                "guess","numeric"))
names(Nerf) <- c("Time","Blaster","Modified","DartType",
                 "DartNumber","Distance")

# Convert factors
Nerf$Blaster <- factor(Nerf$Blaster)
Nerf$Modified <- factor(Nerf$Modified)
Nerf$DartType <- factor(Nerf$DartType)

# Define a function to extract last character
substrRight <- function(x, n){
  substr(x, nchar(x)-n+1, nchar(x))
}

# Extract last character from 'DartNumber' and convert to numeric
Nerf$DartNumber <- as.numeric(substrRight(Nerf$DartNumber,1))

# Convert 'Time' column to POSIXct format
Nerf$Time <- ymd_hms(Nerf$Time)

# Create an interactive box plot using plotly
boxplot <- plot_ly(data = Nerf, x = ~Blaster, y = ~Distance,
                   type = "box", color = ~Blaster,
                   colors = c("#FFA500", "#0000FF"),
                   boxpoints = "all", jitter = 0.5) %>%
  layout(title = "Box Plot of Dart Distance by Blaster Type",
         xaxis = list(title = "Blaster Type"),
         yaxis = list(title = "Distance (feet)"),
         boxmode = "traditional")

# Display the plot
boxplot
## Warning: 'layout' objects don't have these attributes: 'boxmode'
## Valid attributes include:
## '_deprecated', 'activeshape', 'annotations', 'autosize', 'autotypenumbers', 'calendar', 'clickmode', 'coloraxis', 'colorscale', 'colorway', 'computed', 'datarevision', 'dragmode', 'editrevision', 'editType', 'font', 'geo', 'grid', 'height', 'hidesources', 'hoverdistance', 'hoverlabel', 'hovermode', 'images', 'legend', 'mapbox', 'margin', 'meta', 'metasrc', 'modebar', 'newshape', 'paper_bgcolor', 'plot_bgcolor', 'polar', 'scene', 'selectdirection', 'selectionrevision', 'separators', 'shapes', 'showlegend', 'sliders', 'smith', 'spikedistance', 'template', 'ternary', 'title', 'transition', 'uirevision', 'uniformtext', 'updatemenus', 'width', 'xaxis', 'yaxis', 'barmode', 'bargap', 'mapType'