--- title: "Module 2, Assignment 2: From Data to Plot" author: "Ellen Bledsoe, Lily McMullen" format: html execute: eval: false --- ```{r} #| include: false knitr::opts_chunk$set(echo = TRUE) ``` # Assignment Details ### Purpose The goal of this assignment is to practice developing successful workflows to get from the starting data to a plot. ### Task Write R code which produces the correct answers and reflect on workflow. ### Criteria for Success - Code is within the provided code chunks - Code is commented with brief descriptions of what the code does - 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 - Written answers address the questions in sufficient detail # Assignment Questions Our goal for this assignment is to start with a data frame of data, summarize the data in constructive ways, and plot the data to answer some questions. To get from Point A to Point D requires some planning. In this assignment, we will first make a plan, execute how we would actually go about the process, and then evaluate how well our original plan matches with the path we actually used. ## Data Summary The aquaculture scientists on Team Antarctica have been working on developing a new diet for tilapia (a type of fish) based on soy-protein, and they are interested in whether incorporating this into fish diets will result in faster growth rates. They are measuring the amount of growth based on the change in the weight of each fish after 30 days on the new diet. They've provided us with the data below to analyze. First, let's take a look at the data we will be using for the assignment. 1. As always, we start by loading the `tidyverse`. (1 point) ```{r} ``` 2. Next, we need to load in our tilapia growth dataset. Call the data frame `growth`. Then use both the `head` and `tail` functions to take a look at the data. (1 point) ```{r} ``` 3. Before we can plan any strategy, we need to understand the data that we have. Answer the following questions about the data. (0.5 points each, 2 points total) a\. What does one row represent? (One tank? One temperature? One treatment? One fish?) b\. How many tanks of fish were sampled? c\. How many fish were sampled? d\. How many different soy protein levels (treatments) are there? ## Our Tasks We have been asked by our aquaculture specialists to provide them with the following: a. a data frame with the average growth of fish per diet treatment (`soy_protein`); growth is being measured by the change in weight of each fish after 30 days on the diet (`day_30_weight`). b. a plot that shows the relationship (or lack thereof) between the amount of soy protein in the diet and how much the fish have grown c. a data frame with the average growth for each combination of diet treatment *and* tank category (warm or cold) d. a plot that shows the relationship (or lack thereof) between average tank temperature, the amount of growth, and the amount of soy in the diet. They've also asked that we provide all weights in kilograms instead of grams (the `day_30_weight` is currently in grams). ## Prediction 4. Spend some time thinking about each one of these steps. What steps will you need to take to produce the end result? What data frame will you use? What columns will you use? What functions will you use? How will you plot things? For each of the 4 tasks listed above in "Our Tasks," *describe* (do NOT code) how you will get from the starting point (a data frame) to the result (another data frame or a plot). This question will be graded *only on completion*, not on whether or not your plan is correct. (2 points) *Task (a)*: *Task (b)*: *Task (c)*: *Task (d)*: ## Execution Now let's actually go ahead and complete our tasks with code. **NOTE! We need to run the line of code below. This line of code tells R that we want the soy protein levels to be listed in a specific order (low to very high) rather than alphabetically.** ```{r} growth <- growth %>% mutate(soy_protein = factor(soy_protein, levels = c("low", "medium", "high", "very high"))) ``` Because the aquaculture team has asked for everything to use kilograms instead of grams, it makes sense for us to add a column with the fish weights in kilograms (kg) instead of grams (g) to our data frame before we tackle any of the specific tasks. 5. Use the `mutate()` function to add a `day_30_weight_kg` column to the growth data frame with the weights in kilograms. (Hint: there are 1000 grams in 1 kilogram) Save the output as `growth_kg` (2 points) **NOTE: This is the data frame you will use for the remainder of the assignment.** ```{r} ``` ### Task (a) **A data frame with the average growth of fish per diet treatment** 6. Create a new data frame called `growth_by_treatment` with the average growth for each level of soy protein. Remember to use the `growth_kg` data frame as your starting point. (2 points) ```{r} ``` ### Task (b) **A box plot that shows the relationship (or lack thereof) between the amount of soy protein in the diet and the weight at 30 days (growth)** Based on the values we calculated in task (a), it looks like there is probably a positive relationship between the percent of soy protein in tilapia diet and growth. Let's plot the data to confirm. 7. Make a box plot to show this relationship. Change the axis labels to be more easily understood and add a theme. (2 points) (Hint: because we want to plot *all* of the values, not just the mean values, we need to use the original `growth_kg` data frame, not the data frame we created in task (a)) ```{r} ``` ### Task (c) **A data frame with the average growth for each combination of diet treatment *and* tank category** 8. Create a new data frame called `growth_by_temp_treatment`. It should have groups for each combination of the amount of soy protein and whether tanks are warm or cold. Remember, you can create groups with multiple columns! Calculate the average growth for each combination. (2 points) ```{r} ``` ### Task (d) **A scatter plot that shows the relationship (or lack thereof) between average tank temperature and the weight at 30 days** Based on our results above, do we think the tank being warm or cold has much of an influence? Let's plot our data to confirm. 9. Make a multiple scatter plot with the average water temperature in the tank on the x-axis (the actual number, not whether the tank is "cold" or "warm") and the amount of growth on the y-axis (vertical). Change the color of each point so that they represent the amount of soy protein in the diet. Change the axis labels to be more easily understood and add a theme. (2 points) (Hint: because we want to plot *all* of the values, not just the mean values, we need to use the original `growth_kg` data frame) ```{r} ``` As suspected, there doesn't seem to be much of a difference based on tank temperatures. ## Reflection 10. Imagine we had decided to treat `soy_protein` as a continuous variable. What type of plot would we have used for task (b)? Would we have been able to complete task (d)? Why or why not? (2 points) *Answer*: 11. Write 3-5 sentences about if and how your predictions and execution differed and what you learned through the process. (3 points) *Examples of questions to answer: How did your initial prediction of how you expected to accomplish the 4 tasks match up with how we actually went about doing it? Were they similar? Were there common mistakes that you made beforehand? Did you plan a different execution from what we did above that you think would also work?* *Answer*: # Turning in Your Assignment 1. Make sure your name is filled in at the top of the document. 2. 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. 3. To download the HTML file from Posit Cloud, click the empty box to the left of it in the Files panel. 4. Click the blue gear at the top of the Files panel and choose Export. 5. Put your last name at the front of the file name when prompted, then click Download. The file is now in your Downloads folder.