Skip to content

Instantly share code, notes, and snippets.

@dgkeyes
Created April 26, 2019 14:13
Show Gist options
  • Save dgkeyes/6e9e5cfcf67755ba5470525bd3e3fce6 to your computer and use it in GitHub Desktop.
Save dgkeyes/6e9e5cfcf67755ba5470525bd3e3fce6 to your computer and use it in GitHub Desktop.
themes solutions
# Themes
Install and load the [`hrbrthemes` package](https://hrbrmstr.github.io/hrbrthemes/index.html). It's a package that provides some great default themes.
It's not available on CRAN, where we normally install packages from, which means you have to install it slightly differently. You'll use the `devtools` package and then use this to install the `hrbrthemes` package. Use the code below.
```{r}
# install.packages("devtools")
# devtools::install_github("hrbrmstr/hrbrthemes")
library(hrbrthemes)
```
Then add the `theme_ipsum` to your plot.
```{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 = "") +
theme_ipsum()
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment