Created
April 26, 2019 03:52
-
-
Save dgkeyes/2376427de6f510d3d0a3bd5a9013fb70 to your computer and use it in GitHub Desktop.
plot labels solutions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Plot Labels | |
Use the code chunk from above with `geom_text` (not the last one with `geom_label`). Do the following: | |
1. Add a title | |
2. Add a better y axis label | |
3. Remove the x axis label | |
4. Remove the legend (hint: use the `show.legend` argument again) | |
```{r} | |
ggplot(data = sleep_by_gender, | |
mapping = aes(x = gender, | |
y = avg_sleep, | |
fill = gender)) + | |
geom_col(show.legend = FALSE) + | |
geom_text(aes(label = round(avg_sleep, 1)), | |
vjust = 1.5, | |
color = "white") + | |
scale_fill_brewer(palette = "Dark2", | |
na.value = "blue") + | |
scale_y_continuous(limits = c(0, 8), | |
breaks = c(0, 1, 2, 3, 4, 5, 6, 7, 8)) + | |
labs(title = "Women sleep slightly more than men on average", | |
y = "Hours of sleep per night", | |
x = "") | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment