This lab introduces core plotting functions in order to create customized graphics in R.
You can create a new RMarkdown file, or download the LAB-03 RMD template:
You will use the following functions:
The data comes from the Lahman baseball data package. The Teams dataset contains season statistics for each baseball team from the late 1800s onward. The graph reports average strike-outs per game, which is calculated as ave.so below:
You will need only the average strike-outs per game, and the year variables:
Min. | 1st Qu. | Median | Mean | 3rd Qu. | Max. | NA’s |
---|---|---|---|---|---|---|
0 | 3.476 | 4.951 | 4.811 | 6.089 | 9.525 | 120 |
Note that you don’t have to understand baseball to make the graphic.
Your task is to replicate as closely as possible the graphic published by the NYT.
Use 1900 as the starting year for the graph and 2025 as the end point using the xlim=c() argument in the plot.window() function.
# create the league average vector
league.ave <- tapply( X=ave.so, INDEX=as.factor(year), FUN="mean", na.rm=T )
league.year <- as.numeric( names( league.ave ) )
plot.new()
plot.window( xlim=c( 1920, 1980 ), ylim=c( ave.so.min, ave.so.max ) )
points( year, ave.so, col=gray( level=0.2, alpha=0.1 ), pch=17, cex=3 )
points( league.year, league.ave, type="b", pch=8, col="red" )
For example:
Your final plot should be as similar as possible to the NYT graphic!
If you need help looking up arguments remember these two helpful functions:
Login to Canvas at http://canvas.asu.edu and navigate to the assignments tab in the course repository. Upload your HTML file and RMD file to the appropriate lab submission link.
Remember to: