22.4 Exercises

Exercise 22.1 Using the code to produce Figure 22.5:

  1. Adjust the alpha level to a number between 0 and 1. What does that do to the plot?
  2. Adjust the fill level to a color of your choosing. A list of R Colors can be found here: http://www.cookbook-r.com/Graphs/Colors_(ggplot2)/
 
Exercise 22.2 Read the Chapter 12 in R for Data Science: https://r4ds.had.co.nz/tidy-data.html. In this chapter you will learn about tidy data. Explain what tidy data is and the potential uses for pivoting data wider or longer.
 
Exercise 22.3 Look at the documentation for quantile (remember you can type ?quantile at the command line to see the associated help for this function.) Change the ensemble average in quantile_table to compute the 25%, 50%, and 75% percentile. Finally, produce a ensemble average plot of this percentile. How does your result compare to Figure 22.5?

 

Exercise 22.4 Take the data frame try1 from the simulations of the logistic equation and generate an ensemble average (median with 95% confidence interval) of the different simulations and make a plot of the ensemble average without the different simulations.

 

Exercise 22.5 Using the data frame my_table, compare the following code below. The data frame table1 is skinny and long, and the second data frame table2 is called short and wide. Why did we need to make this data frame short and wide for plotting?

# First code chunk
table1 <- my_table %>%
  rowwise(t) %>%
  summarise(q_val = quantile(c_across(starts_with("sim")),
                                probs = quantile_vals),
            q_name = quantile_vals)

# Second code chunk
table2 <- my_table %>%
  rowwise(t) %>%
  summarise(q_val = quantile(c_across(starts_with("sim")),
                                probs = quantile_vals),
            q_name = quantile_vals) %>%
  pivot_wider(names_from = "q_name",values_from="q_val",names_glue = "q{q_name}")