I'm trying to plot the relationship between Batting Average and On Base Percentage and how it changes from week to week.
Below, i exported data from Game Changer (web.gc.com) and used a scatterplot with points\labels that intersect a player at BattingAVG and OnBasePercentage. The teamstats_week1.csv contains the totals stats for each player and obviously data changes week to week.
I'll need to export the new totals CSV file each week (teamstats_week1.csv, teamstats_week2.csv, etc). My question is how can i take multiple CSV files, plot the point, then show movement of those points (good or bad) throughout the course of the season?
library(tidyverse)
library(ggrepel)
# read CSV from current working directory.
# the CSV file was exported from web.gc.com and renamed teamstats.csv
# teamstats_week1.csv should be in the same directory as the R Script
# first row is skipped since it doesn't contain any relevant information
gc_read_csv <- read.csv("teamstats_week1.csv", skip = 1, stringsAsFactors = FALSE)
# create new data frame gc_team_select
gc_team_select <- gc_read_csv %>%
mutate(BattingAVG = as.double(AVG) * 1000, OnBasePercentage = as.double(OBP) * 1000, GamesPlayed = as.numeric(GP), PlayerNumber = as.integer(Number)) %>%
select(PlayerNumber, First, GamesPlayed, BattingAVG, OnBasePercentage) %>%
filter(PlayerNumber < 100) %>%
filter(GamesPlayed > 6)
# plot BattingAVG and OnBasePercentage
ggplot(data = gc_team_select, mapping = aes(x = BattingAVG, y = OnBasePercentage)) +
geom_point() +
geom_text_repel(aes(label = First), size = 3)