README.md

redbull

The redbull package contains ggplot2 colour themes for use in Red Bull Data Science projects.

Installation

You can install redbull from github with:

# You need to install the 'devtools' package first
devtools::install_github("deathbydata/redbull")

The Palettes

There are several colours and palettes built in to the package. Additions and modifications are welcomed! See the palettes.R file for the details.

Usage

Usage is through the functions scale_fill_redbull and scale_colour_redbull depending on your plot aesthetic.

library(ggplot2)
library(redbull)
library(magrittr)

# Using colour aesthetic (points/lines)
mtcars %>% 
  ggplot(aes(x = wt, y = mpg, colour = as.factor(cyl))) + 
  geom_point(size = 4, alpha = 0.75) + 
  scale_colour_redbull()

# Using fill aesthetic (bars/areas)
mtcars %>% 
  ggplot(aes(x = as.factor(carb), fill = as.factor(carb))) + 
  geom_bar() + 
  scale_fill_redbull("rbfull")

You can use discrete = FALSE if you have continuous values. reverse = TRUE will flip the direction of the colours in the palette.

mtcars %>% 
  ggplot(aes(x = disp, y = wt, colour = hp)) + 
  geom_point(size = 4.5, colour = "black") +
  geom_point(size = 4) + 
  scale_color_redbull("rbwarm", discrete = FALSE, reverse = TRUE) +
  ggtitle("Relationship between engine weight and displacement",
          "Colour shows engine horsepower") +
  xlab("Engine displacement (cc)") +
  ylab("Engine weight (?)")

For discrete scales you can select the behaviour when there are more levels of your factor than palette colours using the rep parameter.

mtcars %>% 
  ggplot(aes(x = as.factor(carb), fill = as.factor(carb))) + 
  geom_bar() + 
  scale_fill_redbull("rbyellowgrey", rep = TRUE)

mtcars %>% 
  ggplot(aes(x = as.factor(carb), fill = as.factor(carb))) + 
  geom_bar() + 
  scale_fill_redbull("rbyellowgrey", rep = FALSE)

theme_rb

The redbull package also contains a full ggplot2 theme which you can apply using theme_rb(). To use this as the default theme for all charts in your script or notebook use theme_set(theme_rb()).

theme_set(theme_rb())

mtcars %>% 
  ggplot(aes(x = disp, y = wt, colour = hp)) + 
  geom_point(size = 4.5, colour = "black") +
  geom_point(size = 4) + 
  scale_color_redbull("rbwarm", discrete = FALSE, reverse = TRUE) +
  labs(title = "Relationship between engine weight and displacement",
       subtitle = "Colour shows engine horsepower",
       caption = "Source: R mtcars dataset") +
  xlab("Engine displacement (cc)") +
  ylab("Engine weight (?)")



deathbydata/redbull documentation built on May 23, 2019, 9:49 a.m.