This is an R Markdown Notebook. When you execute code within the notebook, the results appear beneath the code.

Try executing this chunk by clicking the Run button within the chunk or by placing your cursor inside it and pressing Cmd+Shift+Enter.

# Load the necessary libraries
library(googlesheets4)
library(viridis)
## Loading required package: viridisLite
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
# Read in the Data
URL <- "https://docs.google.com/spreadsheets/d/1Ap5h86minzUi-wOqE9SREHGCa_nGTDPspa7V5WFDnEI/edit?usp=sharing"
DATA <- read_sheet(URL)
## ! Using an auto-discovered, cached token.
##   To suppress this message, modify your code or options to clearly consent to
##   the use of a cached token.
##   See gargle's "Non-interactive auth" vignette for more details:
##   <https://gargle.r-lib.org/articles/non-interactive-auth.html>
## ℹ The googlesheets4 package is using a cached token for
##   'jvaugh30@vols.utk.edu'.
## ✔ Reading from "Mario Kart Survey (Responses)".
## ✔ Range 'Form Responses 1'.
# Get rid of the Timestamp Column
DATA <- DATA[,-1]

# Rename the columns for easier coding
colnames(DATA) <- c("StudentPlaying", "Time", "Experience", "ControllerType", "Course", "CC", "NumItemsUsed", "CharacterPlayed", "CoinCount", "SwitchScreen", "PlaceInRace")

# Get rid of potential duplicates by putting them in all capital letters
DATA$CharacterPlayed <- toupper(DATA$CharacterPlayed)

# Define Mario Kart color palette
mario_palette <- c(
  "#fcba03",  # Yellow (Mario)
  "#0089f5",  # Blue (Yoshi)
  "#f70000",  # Red (Bowser)
  "#00c808",  # Green (Luigi)
  "#ff7d00"   # Orange (Donkey Kong)
)

# Fit a linear model
lm_fit <- lm(NumItemsUsed ~ Time, data = DATA)

# Extract the slope and intercept
slope <- coef(lm_fit)[[2]]
intercept <- coef(lm_fit)[[1]]

# Plot
p <- ggplot(DATA, aes(x = Time, y = NumItemsUsed, color = Course)) +
  geom_point(size = 1.75) +
  scale_color_manual(values = mario_palette) +
  labs(title = "Scatter Plot of Time vs. Number of Items Used",
       x = "Time",
       y = "Number of Items Used",
       color = "Course") +
  theme_minimal() +
  theme(legend.position = "right") +
  geom_abline(intercept = intercept, slope = slope, color = "black")

# Make the plot interactive using Plotly
ggplotly(p)