I am using the Lahman library to get data for baseball results, and in the code below, I calculated the OPS. But now I need help with calculating for every year the correlation between runs per game (R/G) and OPS and plotting these correlations as a function of year. Could you please help?
library (Lahman)
Teams %>% filter(yearID == 2002) %>%
mutate(pa = AB + BB, BBPA=BB/pa, Singles = (H-X2B-X3B-HR)/G, Doubles=X2B/G,
Triples=X3B/G, HRAB=HR/AB) %>%
mutate(OPS=BBPA+Singles+2*Doubles+3*Triples+4*HRAB) %>% select(OPS,R)

