# Load necessary packages
library(ggplot2)
library(gsheet)
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
# Import data
ranking <- gsheet2tbl("https://docs.google.com/spreadsheets/d/1Ap5h86minzUi-wOqE9SREHGCa_nGTDPspa7V5WFDnEI/edit#gid=408435445")
## No encoding supplied: defaulting to UTF-8.
NAMES <- c("Date", "Name", "Time", "Experience",
"Controller", "Course", "CC", "Items Used",
"Character", "Coins", "Switch", "Place")
names(ranking) <- NAMES
# Filter out N/A values
ranking <- ranking[complete.cases(ranking$`Items Used`, ranking$Place), ]
# Scatterplot aesthetics with line of best fit
p <- ggplot(ranking, aes(x = `Items Used`, y = Coins)) +
geom_point(color = "#1f77b4", size = 3) + # Blue color for data points
geom_smooth(method = "lm", se = FALSE, color = "red") + # Add a line of best fit
labs(x = "Items Used", y = "Coins") +
theme_minimal() +
ylim(0, 20) # Set y-axis limits
# Convert to interactive plot
ggplotly(p)
## `geom_smooth()` using formula = 'y ~ x'