@@ -291,6 +291,12 @@ hidden?
291
291
>
292
292
> - Replace the box plot with a violin plot; see ` geom_violin() ` .
293
293
>
294
+ > ``` {r, answer=TRUE, purl=FALSE}
295
+ > ggplot(data = surveys_complete, mapping = aes(x = species_id, y = weight)) +
296
+ > geom_jitter(alpha = 0.3, color = "tomato") +
297
+ > geom_violin()
298
+ > ```
299
+ >
294
300
> In many types of data, it is important to consider the *scale* of the
295
301
> observations. For example, it may be worth changing the scale of the axis to
296
302
> better distribute the observations in the space of the plot. Changing the scale
@@ -299,24 +305,39 @@ hidden?
299
305
>
300
306
> - Represent weight on the log~10~ scale; see `scale_y_log10()`.
301
307
>
308
+ > ```{r, answer=TRUE, purl=FALSE}
309
+ > ggplot(data = surveys_complete, mapping = aes(x = species_id, y = weight)) +
310
+ > scale_y_log10() +
311
+ > geom_jitter(alpha = 0.3, color = "tomato") +
312
+ > geom_boxplot(outlier.shape = NA)
313
+ > ```
314
+ >
302
315
> So far, we've looked at the distribution of weight within species. Try making
303
316
> a new plot to explore the distribution of another variable within each species.
304
317
>
305
318
> - Create boxplot for `hindfoot_length`. Overlay the boxplot layer on a jitter
306
319
> layer to show actual measurements.
307
320
>
321
+ > ```{r, answer=TRUE, purl=FALSE}
322
+ > ggplot(data = surveys_complete, mapping = aes(x = species_id, y = hindfoot_length)) +
323
+ > geom_jitter(alpha = 0.3, color = "tomato") +
324
+ > geom_boxplot(outlier.shape = NA)
325
+ > ```
326
+ >
308
327
> - Add color to the data points on your boxplot according to the plot from which
309
328
> the sample was taken (`plot_id`).
310
-
329
+ >
311
330
> Hint: Check the class for `plot_id`. Consider changing the class of `plot_id`
312
331
> from integer to factor. Why does this change how R makes the graph?
313
332
314
333
```{r boxplot-challenge, eval = FALSE, purl = TRUE, echo = FALSE}
315
334
## Challenge with boxplots:
316
335
## Start with the boxplot we created:
317
336
ggplot(data = surveys_complete, mapping = aes(x = species_id, y = weight)) +
318
- geom_boxplot(alpha = 0) +
319
- geom_jitter(alpha = 0.3, color = "tomato")
337
+ geom_jitter(alpha = 0.3, color = "tomato") +
338
+ geom_boxplot(outlier.shape = NA)
339
+ ## By ordering the geom layers like this, we can make sure that the boxplot is
340
+ ## layered over the jittered points.
320
341
321
342
## 1. Replace the box plot with a violin plot; see `geom_violin()`.
322
343
0 commit comments