--- title: "R Workshop Series - Assignment 2" author: "Your Name Here" date: "Due: Wednesday, April 21, 2021" output: html_notebook --- # Introduction In this assignment, we are going to review graphing in R Studio, using mainly **ggplot** but also using **plotly**. As I said in the presentation, please try to use Google as much as possible for working through the assignment. If you cannot find a solution with it, my email is erg5331@psu.edu. I will also hold two office hours for each assignment. If you cannot attend these, please email me with questions. Put the assignment and question number in the subject of your email, and we can either schedule a 1-on-1 Zoom "office hours" for help or we can engage in a discussion through email. With that said, here is the assignment! # Load Packages For this assignment, we will need to use the packages for graphing (hint: there are 2), chaining, wrangling, renumbering, and organizing graphs (hint: there are 2). ```{r} # clear R environment rm(list = ls()) # Use this code chunk to load the 7 packages needed for this assignment. ``` # Import Data In order to graph data, we need to load some data into our R session. We are going to load the final, joined data frames from the previous assignment, labeled "Election2008_Final.csv" and "Election2012_Final.csv". ```{r} # Use this code chunk to load the 2 data frames needed for this assignment. ``` ## Data-Specific Questions Now that we have 2 data frames for each election year (2008 and 2012), we are ready to dig into the data and see what we can find through graphs! Note that each of the tasks will require some data frame wrangling before you create a graph to complete the task. Carefully work through the code and check that every part is answered before submitting the assignment. Remember, you can submit this assignment twice, so the first submission does not have to be perfect if you are just looking for general feedback. A. (6 pts. - **ggplot**) Construct a bar graph of total votes in each state for both elections. Make sure the states' names on the axis ticks are legible and that there are titles on the graph and axes. Ensure that the axes' tick marks are *not* scientific numbers. ```{r} ``` B. (2 pts. - **ggplot**) Construct a scatterplot showing the relationship between President Obama's vote totals in each election. Then, graph a line of best fit. Finally, give the graph a title and label the axes. Ensure that the axes' tick marks are *not* scientific numbers. ```{r} ``` C. (8 pts. - **ggplot**) Construct a boxplot for each of the candidates' vote totals in the 2008 election, focusing only on states located in the SW of the country. Use the log() of the vote totals in each state so each party can be seen. (Hint: There should be one boxplot for each state and you will need to join them using the **grid** and **gridExtra** packages.) Color each boxplot by the party's associated color as assigned here: Democratic = Blue, Republican = Red, Independent = Purple, Libertarian = Yellow/Gold, Constitution = Brown, Green = Green, Other = Gray. Add a title and axes labels for each individual graph and an overall title for the combined graphic. ```{r} ``` D. (4 pts. - **plotly**) Construct a pie chart that shows the percentage of 2012 election vote from each region of the country. Color each "piece" using the same colors from the presentation file. Additionally, add a title to the chart. ```{r} ``` # Conclusion Constructing graphs in R can be difficult, especially if this is your first time doing something like this assignment. For that reason, do not hesitate to come to office hours or individually email me for help! Once you are comfortable with your progress, email a PDF document or HTML notebook to me at erg5331@psu.edu so I can assess your work. I will comment on your work and give you another chance to submit the assignment if you did not get a 100% on the first submission. I appreciate you taking the time to come to the workshops and complete each of the assignments, and I wish you luck in completing the final project, which is due on Monday, April 26, 2021 by 12:00 AM EST.