library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.2 ✔ readr 2.1.4
## ✔ forcats 1.0.0 ✔ stringr 1.5.0
## ✔ ggplot2 3.4.3 ✔ tibble 3.2.1
## ✔ lubridate 1.9.2 ✔ tidyr 1.3.0
## ✔ purrr 1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(ggplot2)
library(dbplyr)
##
## Attaching package: 'dbplyr'
##
## The following objects are masked from 'package:dplyr':
##
## ident, sql
library(ggthemes)
library(ggrepel)
week3_dataset <- read.csv("baseball.csv",header = TRUE)
Question 1 RankSeason: I think this is really confusing to me because of the name of this variable. Usually in the MLB they will only have ranking in their own division not in the entire league. This will be more clear if it is named “playoffSeeding” OOBP/OSLG: The NA in this column is too much. I think this stats ins’t that hard to collect RankPlayoffs: I think this column needs to distinct the two leagues. Since Their will be two third, fourth, fifth place in the same year.
Question2 RS in 1968: The avg RS in that year is significantly lower then other years. I am guessing their is a rule changed in that year and player did not have time to adopt the new rules yet.
Question3
run_score <- week3_dataset%>%
group_by(Year)%>%
summarise(AVG_RS=mean(RS),AVG_AVG=mean(BA))
percentiles <- c(quantile(run_score$AVG_RS, 0.01),
quantile(run_score$AVG_RS, 0.99))
run_score %>%
ggplot()+
geom_jitter(mapping = aes(x = AVG_RS, y = ""),
width = 0, height = 0.1)+
geom_vline(mapping = aes(xintercept = percentiles["1%"],
color = "2% percentile"))+
geom_vline(mapping = aes(xintercept = percentiles["99%"],
color = "98% percentiles"))+
geom_text_repel(data = filter(run_score, AVG_RS < 600),
mapping = aes(x = AVG_RS, y = "", label = Year),
color = "darkred")