Quiz-2

Short answer + common missed question solutions

Question 7: See the help file for geom_jitter here.

True or False: Two classmates that run the following code at the same time will get the exact same plot.

Read the help file for geom_jitter, and think critically about the following: “It adds a small amount of random variation to the location of each point.” Random variation is a random process, and will not be the same when you run it again (unless you use set.seed, which this code does not).

The correct answer is ‘False’.

Question 8: Suppose you are trying to make a segmented bar plot of penguin species by their flipper length. You write the following code:

and you get the following error:

Using the code and the error message, explain why the code isn’t working Explain how you could fix this code to create a segmented bar plot

geom_bar() performs a statistical transformation to the data, and plots that transformation (count) onto our y-axis. The function geom_bar() does not take a y input in the aes. This is what the error is saying when it says “must only have an x or y aesthetic.

We could adhere to the error message and only input an x aes. We could then change y to fill to create a segmented bar plot.

Question 10:

Identify how this graph can be improved. Provide the function in R that could be used to improve this graph.

This is the example in the scale_colour_viridis help file. In class, we talked at length about the importance of an effective color pallet, that is also inclusive to a more general audience.

Identifying that this is an issue, we can use scale_colour_viridis_c to quickly change the color pallet to something more color blind friendly. It is especially important that this is _c because the plot is colored by a continuous variable. We use _d for discrete variables.

Another acceptable answer is identifying that there are no units on either the x or y axis, and that we can use the labs() function to help change this. Simply stating that the labels needed to be more descriptive is not enough detail, nor is it enough to say that they need to be capitalized (subjective).

Answers that are subjective, such as making a different plot (i.e. a scatter plot) is not appropriate for this context. A heat map is a justifiable way to represent three quantitative variables. A different plot may be more appropriate, but it’s hard to know without more context.

This is different than say making a bar plot of one quantitative and one categorical variable (which we know is inappropriate), and saying a boxplot would be more appropriate.