DS4PS / cpp-526-fall-2020

Course shell for CPP 526 Foundations of Data Science I for Fall 2020
http://ds4ps.org/cpp-526-fall-2020/
MIT License
3 stars 1 forks source link

Legend help #12

Open AprilPeck opened 4 years ago

AprilPeck commented 4 years ago

I'm down to just 2 questions left on Lab 3!

  1. Is the "Strikeouts per game per team" part of the legend?
  2. I can't figure out how to get the line in the legend the same as it is on the NYT graphic. I've googled and everything I see shows just a line with a dot in the middle, which is what I'm getting. Is there a way to get the line with a dot on each end? This is what I have right now for the legend:

legend("topleft", legend = "League Average", col = "steel blue",pch = 16, lwd = 3, bty = "n", xjust = 0, text.col = "steel blue", cex = 1.5,)

lecy commented 4 years ago

You can add a dumbbell using segments:

segments( x0=1920,  x1=1925, y0=5 )
points( c(1920,1925), c(5,5), pch=19 )

https://stat.ethz.ch/R-manual/R-devel/library/graphics/html/segments.html

jamisoncrawford commented 4 years ago

Thanks, @lecy! @AprilPeck, as counter-intuitive as it may seem, I would recommend against using the legend function and instead using the "dumbbell" code @lecy provided, as well as function text(), with the correct coordinates, to create a custom lab. Like how we discussed the use of plot() and the defaults elements it provides, legend() can be slightly restrictive compared to inserting custom graphical elements with points(), segments(), and text().

If legend() works for you, though, all the better!

AprilPeck commented 4 years ago

Thank you!