Please spend a few minutes reading through the notes from Lecture 2. Like in Problem Set 1, you should go through each code block with someone in your group and see if you can both explain to each other what all of the code does.
In lecture, Prof. Wyner discussed the relationship between a team’s payroll and its winning percentage. We will create plots from his analysis in the following problems using the dataset “mlb_relative_payrolls.csv”, which you can find in the “data/” folder of your working directory. You should save all of the code for this analysis in an R script called “ps2_mlb_payroll.R”.
If you don’t have the dataset in your data folder yet, download it from the GitHub page here.
## Parsed with column specification:
## cols(
## Team = col_character(),
## GM = col_character(),
## Team_Payroll = col_double(),
## Winning_Percentage = col_double(),
## Year = col_double(),
## Relative_Payroll = col_double()
## )
Make a histogram of team winning percentages. Play around with different binwidths.
Make a histogram of the relative payrolls.
Make a scatterplot with relative payroll on the horizontal axis and winning percentage on the vertical axis.
Without executing the code below, discuss with your group and see if you can figure out what it is doing.
Execute the code above. What can you say about how team payrolls have evolved over time? Make a similar plot that visualizes how relative payrolls have evolved over time.
Add an appropriate title and relabel the y-axis using the labs()
function to the plot above.