# Set a minimum threshold for total minutes played
min_minutes <- 1000
# Filter dataset to include players with at least 'min_minutes'
filtered_nba_data <- nba_players_clean %>%
filter(TotalMinutes >= min_minutes) # Replace 'TotalMinutes' with your actual column name
# Scatterplot: Salary vs. True Shooting Percentage (TS%)
scatter_salary_ts <- ggplot(filtered_nba_data, aes(
x = TS_pct, y = Salary_Millions,
text = paste(
"<b>Player:</b>", PlayerName,
"<br><b>TS%:</b>", scales::percent(TS_pct, accuracy = 0.1),
"<br><b>Salary:</b>", scales::dollar(Salary_Millions, prefix = "$", suffix = "M"),
"<br><b>Total Minutes Played:</b>", TotalMinutes
)
)) +
geom_point(color = "#1f78b4", alpha = 0.8, size = 2) + # Blue points with transparency
geom_smooth(method = "lm", se = FALSE, color = "#ff7f00", size = 1.2) + # Orange trend line
labs(
title = "Interactive Scatterplot: Salary vs. True Shooting Percentage (TS%)",
subtitle = paste("Players with at least", min_minutes, "Total Minutes Played"),
x = "True Shooting Percentage (TS%)",
y = "Salary (in Millions)"
) +
scale_x_continuous(
labels = scales::percent_format(),
limits = c(0.45, 0.75),
breaks = seq(0.45, 0.75, by = .05), # Assuming TS% ranges between 40% and 70%
expand = c(0, 0)
) +
scale_y_continuous(
labels = scales::dollar_format(prefix = "$", suffix = "M"),
limits = c(0, 50), # Assuming salary ranges up to $50M
expand = c(0, 0)
) +
theme_minimal(base_size = 14, base_family = "Arial") +
theme(
plot.title = element_text(face = "bold", size = 16, hjust = 0.5),
plot.subtitle = element_text(face = "italic", size = 12, hjust = 0.5, color = "gray40"),
axis.title.x = element_text(face = "italic", size = 12),
axis.title.y = element_text(face = "italic", size = 12),
axis.text = element_text(size = 10),
panel.grid.major = element_line(color = "gray80", size = 0.5),
panel.grid.minor = element_blank(),
legend.position = "none"
)