DS4PS / cpp-526-spr-2021

Course shell for Foundations of Data Science I
https://ds4ps.org/cpp-526-spr-2021/
MIT License
1 stars 2 forks source link

Lab 3- Questions #5

Open AhmedRashwanASU opened 3 years ago

AhmedRashwanASU commented 3 years ago

@jamisoncrawford,

1 - As I noticed that Lab 3 has 3 questions, where 1 & 2 code is provided, do we need to modify the codes in order to get the desired plots?

2- for question 3 is it asking to combine both of the codes in order to get the full detailed plot?

jamisoncrawford commented 3 years ago

@AhmedRashwanASU this lab's template walks you through the first few steps of creating the visualization. It's up to you whether you want to follow a step-by-step approach to show your audience how you built the visualizations, or if you simply want to combine all of the steps into a single code chunk and show the final visualization. Does this make sense?

Above all, you need to reproduce the NYT visualization as closely as possible using R plotting functions. It will take some online research combined with the week's reading and videos.

This older video I created is very helpful in walking you through the techniques you'll need (but not all the way to an exact replication!):

https://youtu.be/unFbaAhgF2E

AhmedRashwanASU commented 3 years ago

Thank you for the clarification, will follow the readings to get this nailed..

kpalmer7113 commented 3 years ago

@jamisoncrawford Your video was extremely helpful to get this assignment started. I am now having a terrible time figuring out my margins. The abline() function goes beyond the x-axis and my label for the 2012 league average gets cut off. I attempted to adjust margins through mtext() and can't seem to get it right. Any suggestions?

jamisoncrawford commented 3 years ago

@kpalmer7113 good! Students who explore all the corners of this course are rewarded! (It's just good game design).

So with mtext(), you may find this Stack Overflow thread helpful. If you include the argument xpd = TRUE in your function call to mtext(), it should allow your 2012 callout to overlap the axes without getting cut off (IIRC). Let me know if that works!

The abline() function goes beyond the x-axis

As for abline(), why is it intersecting or going beyond the x-axis, since the NYT baseball graphic doesn't have vertical lines - can you help me understand?

At any rate - try first by adjusting the axis position either vertically or horizontally. If push comes to shove, you can use lines() to individual create and specify each limit for your lines instead of using abline(). However, try adjusting your axis first using the hadj = and padj =. You can read more about the axis() function here. These are just shots in the dark, though, since I'm not sure exactly what you need! Hope this helps!

kpalmer7113 commented 3 years ago

@jamisoncrawford xpd = TRUE did work. Thank you!

I used abline() to draw lines for the y-axis points but it extends to the left of the year 1900. I am trying to adjust the line to begin at 1900.

jamisoncrawford commented 3 years ago

@kpalmer7113 glad that works!

Ah, I understand the issue with abline() (I suspected it was for the horizontal grid lines but I've seen all sorts of funky stuff - and much of it works!). Here's a good thread that discusses limits to gridlines. In short, you may be better off using something like segments() to brute force your gridlines. Here's documentation for the function. You can set arguments y0 = and y1 = to 1, 2, 3, etc. whereas x0 = can be set to "1900" and x1 = set to "2012".

That should do the trick if abline() is being finnicky! Of course, it's not a super flexible solution. It's a bit of a kludge. However, since there aren't many lines, it should be pretty easy to implement and replicate for each gridline. Keep us updated!

AhmedRashwanASU commented 3 years ago

@jamisoncrawford was trying to Emphasize averages in 1924 and 2012 as points, which function would help here?

image

AhmedRashwanASU commented 3 years ago

@jamisoncrawford Holaa just did it using the below parameters ..

points( 1924, 2.7, pch=16, cex=1.2, col="firebrick" )

points( 1924, 2.7, pch=1, cex=2.1, col="firebrick" )

image

lecy commented 3 years ago

Looking good!

The ablines problem highlights the idea of the canvas being the space where all of the drawing functions work.

Figuring out how to annotate data versus how to create axis labels and margin text is the tricky part. Not obvious at first, but helpful for creating fully customized graphics when you understand some of the arguments.

kpalmer7113 commented 3 years ago

Thank you @jamisoncrawford and @lecy. I was able to use segment() to solve the problem. This should be easier too when adding the "Strikeouts per game per team" on line 9.