# Load required packages
library(ggplot2)
library(gganimate)
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(readxl)
# Read the data
Nerf <- read_xlsx("Nerf.xlsx",
col_types = c("date", "text", "text", "text", "text", "numeric"))
names(Nerf) <- c("Time", "Blaster", "Modified", "DartType", "DartNumber", "Distance")
# Convert Time to POSIXct format
Nerf$Time <- as.POSIXct(Nerf$Time)
# Create ggplot object
p <- ggplot(Nerf, aes(x = Time, y = Distance, color = Blaster, text = paste("Blaster: ", Blaster, "<br>",
"DartType: ", DartType, "<br>",
"Distance: ", Distance, "feet"))) +
geom_point() +
labs(title = "Nerf Dart Performance",
x = "Time",
y = "Distance (feet)",
color = "Blaster") +
theme_minimal() +
guides(color = guide_legend(title = "Blaster"))
# Create animated plot
animated_plot <- ggplotly(p) %>%
animation_opts(frame = 2.2) # Set the frame duration to 2.2 seconds
# Print animated plot
animated_plot