Module 2, Assignment 1: Scatter Plots
Assignment Details
Purpose
The goal of this assignment is to assess your ability to produce and interpret scatter plots in both base R and ggplot2.
Task
Write R code which produces the correct answers and text to correctly interpret the plots produced.
Criteria for Success
- Code is within the provided code chunks
- Code chunks run without errors
- Code produces the correct result
- Code that produces the correct answer will receive full credit
- Code attempts with logical direction will receive partial credit
- Code used is based on what we have learned in this course
- Written answers address the questions in sufficient detail
Assignment Questions
For this assignment, we are going to be making plots! We are going to use a data set containing data from a sample of our fish tanks. The data contains information about the tanks sampled and how many sick fish are contained in each tank.
Questions are worth 1 point unless otherwise noted.
First, let’s prepare our data.
- Load the
tidyversepackage into the work space.
- Read in the data using the
read_csv()function. Name the data framesick_fish.
How many rows does the
sick_fishdata frame have? How many columns?Answer:
Use a function (
head(),str(), or another function you prefer) to take a look at the data points in the data frame.
What does one row (observation) represent (e.g., an individual fish?, all fish of a certain species? all tanks of a certain species? etc.)?
Answer:
Based on the column names, briefly describe what data is included in the data frame.
Answer:
Take a look at the columns that have the total number of fish in the tank and the number of sick fish per tank. Determine whether these two columns are numeric or categorical.
Answer:
Plotting with base R
- Using base R (the code we learned in lesson 2.1), create a histogram of the number of sick fish in each tank.
In 2-3 sentences, describe what the histogram tells you about the distribution of the number of sick fish. (2 points)
Answer:
Using base R (the code we learned in lesson 2.1), create a scatter plot. Put the total number of fish on the x-axis and the number of sick fish on the y-axis.
Interpret the scatter plot. What is the plot telling you? Is there a positive or negative relationship between the two variables. What does that mean? (2 points)
Answer:
Using ggplot2
Now, let’s use what we’ve learned about ggplot2 to recreate the same scatter plot. We will do this in 2 steps.
- In the first step, we will add the data, axes, and geom.
- In the second step, we will modify the plot to increase interpretability by renaming axes and adding a theme.
- Create the scatter plot using the proper
geomfunction.
- Now, recreate the plot from Question 12 and add better axes labels and choose a theme to make it clearer to understand.
For each fish species, calculate the average and the standard deviation for the number of sick fish.
Hint: think back to Module 1 and which function we can use to “split, apply, combine”
Based on the summary data you’ve calculated above, do you think the two clumps of data correspond to the two species? Which species seems to be the one that is causing the most problems? (2 points)
Answer:
Do some brainstorming. Based on the plots we’ve made and the calculations we’ve done so far, are we sure that the two clumps of data we see in the data visualization do, in fact, correlate to the two different species? How could we confirm? How might we include that information in the plot? (2 points)
Answer:
Turning in Your Assignment
- Make sure your name is filled in at the top of the document.
- Click the Render button at the top of this document. This will produce an HTML file that opens in a new tab and also saves to the Files panel on the bottom-right of your screen.
- To download the HTML file from Posit Cloud, click the empty box to the left of it in the Files panel.
- Click the blue gear at the top of the Files panel and choose Export.
- Put your last name at the front of the file name when prompted, then click Download. The file is now in your Downloads folder.