Giter Site home page Giter Site logo

redbull's Introduction

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.

  • redbull (default)
  • rbfull
  • rbcool
  • rbwarm
  • rbyellowgrey
  • bloomberg
  • bloombergfull

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 (?)")

redbull's People

Contributors

joshmuncke avatar deathbydata avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.