diff --git a/episodes/visualizing-ggplot.Rmd b/episodes/visualizing-ggplot.Rmd index 6e88a777d..a2aef490c 100644 --- a/episodes/visualizing-ggplot.Rmd +++ b/episodes/visualizing-ggplot.Rmd @@ -319,11 +319,11 @@ ggplot(data = complete_old, mapping = aes(x = plot_type, y = hindfoot_length)) + geom_jitter(alpha = 0.2) ``` -You may have noticed that some of our data points are now appearing on our plot twice: the outliers are plotted as black points from `geom_boxplot()`, but they are also plotted with `geom_jitter()`. Since we don't want to represent these data multiple times in the same form (points), we can stop `geom_boxplot()` from plotting them. We do this by setting the `outlier.shape` argument to `NA`, which means the outliers don't have a shape to be plotted. +You may have noticed that some of our data points are now appearing on our plot twice: the outliers are plotted as black points from `geom_boxplot()`, but they are also plotted with `geom_jitter()`. Since we don't want to represent these data multiple times in the same form (points), we can stop `geom_boxplot()` from plotting them. We do this by setting the `outliers` argument to `FALSE`. ```{r boxplot-outliers, warning = F} ggplot(data = complete_old, mapping = aes(x = plot_type, y = hindfoot_length)) + - geom_boxplot(outlier.shape = NA) + + geom_boxplot(outliers = FALSE) + geom_jitter(alpha = 0.2) ``` @@ -331,7 +331,7 @@ Just as before, we can map `plot_type` to `color` by putting it inside `aes()`. ```{r global-color, warning=FALSE} ggplot(data = complete_old, mapping = aes(x = plot_type, y = hindfoot_length, color = plot_type)) + - geom_boxplot(outlier.shape = NA) + + geom_boxplot(outliers = FALSE) + geom_jitter(alpha = 0.2) ``` @@ -341,7 +341,7 @@ If we want to limit the mapping to a single `geom`, we can put the mapping into ```{r geom-color, warning=FALSE} ggplot(data = complete_old, mapping = aes(x = plot_type, y = hindfoot_length)) + - geom_boxplot(outlier.shape = NA) + + geom_boxplot(outliers = FALSE) + geom_jitter(aes(color = plot_type), alpha = 0.2) ``` @@ -350,7 +350,7 @@ Now our points are colored according to `plot_type`, but the boxplots are all th ```{r reverse-layers, warning=FALSE} ggplot(data = complete_old, mapping = aes(x = plot_type, y = hindfoot_length)) + geom_jitter(aes(color = plot_type), alpha = 0.2) + - geom_boxplot(outlier.shape = NA) + geom_boxplot(outliers = FALSE) ``` Now we have the opposite problem! The white `fill` of the boxplots completely obscures some of the points. To address this problem, we can remove the `fill` from the boxplots altogether, leaving only the black lines. To do this, we set `fill` to `NA`: @@ -358,7 +358,7 @@ Now we have the opposite problem! The white `fill` of the boxplots completely ob ```{r fill-na, warning=FALSE} ggplot(data = complete_old, mapping = aes(x = plot_type, y = hindfoot_length)) + geom_jitter(aes(color = plot_type), alpha = 0.2) + - geom_boxplot(outlier.shape = NA, fill = NA) + geom_boxplot(outliers = FALSE, fill = NA) ``` Now we can see all the raw data and our boxplots on top. @@ -411,7 +411,7 @@ We will create an object called `myplot`. If you run the name of the `ggplot2` o ```{r} myplot <- ggplot(data = complete_old, mapping = aes(x = plot_type, y = hindfoot_length)) + geom_jitter(aes(color = plot_type), alpha = 0.2) + - geom_boxplot(outlier.shape = NA, fill = NA) + geom_boxplot(outliers = FALSE, fill = NA) myplot ``` @@ -471,7 +471,7 @@ Because there are so many possible arguments to the `theme()` function, it can s You may have noticed that we have used 3 different approaches to getting rid of something in `ggplot`: -- `outlier.shape = NA` to remove the outliers from our boxplot +- `outliers = FALSE` to remove the outliers from our boxplot - `panel.grid.major.x = element_blank()` to remove the x grid lines - `legend.position = "none"` to remove our legend