DS4PS / cpp-526-sum-2021

Coure shell for CPP 526.
https://ds4ps.org/cpp-526-sum-2021/
MIT License
1 stars 3 forks source link

Highlighting League Average in Blue #19

Open Julia-Hernandez opened 3 years ago

Julia-Hernandez commented 3 years ago

Hi! I am having trouble highlighting the league average trend line. I have been reviewing the notes ("1.3.7 Highlighting Groups") and it seems like I've tried every combination but keep coming up with the same result. Each time, all the points remain gray and it appears that the graph doesn't change at all. Here is the current code that I have:

yearx.jitter <- Teams$yearID + rnorm( nrow(Teams) ) soy.jitter <- Teams$SO + rnorm( nrow(Teams) )

plot.new() plot.window(xlim = c(1900, 2012), ylim = c(ave.so.min, ave.so.max)) points(x = year, y = ave.so, pch = 16, cex = 0.75, col = "gray85") axis(side = 1, lwd = 2, hadj = 0.5, padj = -1, at = seq(from = 1900, to = 2012, by = 10)) axis(side = 4, lwd = 0, las = 1, col.axis = "gray85", at = seq(from = 0, to = 9, by = 1), font.axis = 2) title( main = "Strikeouts on the Rise") points( year[ league.ave ], ave.so[ league.ave ], pch = 16, cex = 0.75, lwd = 2, col = "dodgerblue4" )

Thanks!

jamisoncrawford commented 3 years ago

Have you tried using point() with a single value for x and y? Argument pch = can be used to make the outline of a circle, col = can change the color, and you can overlay a highlighted circle to reproduce the effect of the NYT graphic. Hope this helps!

lecy commented 3 years ago

Note that the trend line will have a year vector for X (each year occurring one time) and and average vector for Y (one data point in each year).

I don’t think you are using league.ave correctly here as a sub setting variable (not sure how you created it - you didn’t share that code).

It will be something like points( year, league.ave, … )