Code Monkey home page Code Monkey logo

ggroove's Introduction

ggroove

There are two colors in my head. But we’ll need a few more to make plots.

ggroove is a package of color palettes and ggplot2 scale_ functions inspired by various album covers.

Installation

You can install the development version here

remotes::install_github("danovando/ggroove")

Overview

The first entries in the ggroove library come from Radiohead’s studio LPs, which gets a series of specific functions in the form

scale_fill_radiohead_d and scale_color_radiohead_c, where _d indicates discrete and _c indicates continuous.

As other artists are added, you can use color palettes from any included album using

scale_fill_album_d and scale_color_album_c

If you’d like to submit a color palette to ggroove, see instructions here

A quick note, there’s a lot of science out there on how to construct color palettes that accurately convey information.

These are not those.

Color schemes that make for great album art are not necessarily designed to convey information. I wouldn’t recommend using these for continuous color scales, if you’ve got a few discrete categories rock on.

Radiohead Palettes

Pablo Honey

plot_palette(lp = "pablo_honey")

The Bends

plot_palette(lp = "the_bends")

OK Computer

plot_palette(lp = "ok_computer")

Kid A

plot_palette(lp = "kid_a")

Amnesiac

plot_palette(lp = "amnesiac")

Hail to the Thief

plot_palette(lp = "hail_to_the_thief")

In Rainbows

plot_palette(lp = "in_rainbows")

The King of Limbs

plot_palette(lp = "the_king_of_limbs")

A Moon Shaped Pool

plot_palette(lp = "a_moon_shaped_pool")

How to Use

We’ll use data from gapminder and palmerpenguins to demonstrate ggroove.

library(ggplot2)
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(ggroove)
library(palmerpenguins)
library(gapminder)

ggplot2::theme_set(theme_minimal())

gapminder::gapminder %>%
  ggplot(aes(lifeExp, fill =  country)) +
  geom_histogram(show.legend = FALSE) +
  scale_fill_radiohead_d(album = "in_rainbows") +
  theme_minimal()
#> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

gapminder::gapminder %>%
  ggplot(aes(lifeExp, fill =  continent)) +
  geom_histogram(show.legend = FALSE) +
  scale_fill_radiohead_d(album = "ok_computer") +
  theme_minimal() + 
  theme_dark()
#> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

And some discrete penguins as well

penguins %>% 
  ggplot(aes(bill_length_mm, bill_depth_mm, color = species)) + 
  geom_point(size = 4) + 
  scale_color_radiohead_d(album = "in_rainbows", direction = 1)
#> Warning: Removed 2 rows containing missing values (geom_point).

Here’s a continuous colorramp based on The Bends (again, probably best not to use ggroove for continuous scales!)

penguins %>% 
  ggplot(aes(bill_length_mm, bill_depth_mm, color = body_mass_g)) + 
  geom_point(size = 4) + 
  scale_color_radiohead_c(album = "the_bends", direction = -1)
#> Warning: Removed 2 rows containing missing values (geom_point).

Other Artists

You can view all the artists / albums currently present in ggroove by examining the ggroove database in ggroove::ggroove_db

ggroove_db$artist %>% unique()
#> [1] "radiohead"   "the_beatles"
ggroove_db$album %>% unique()
#>  [1] "in_rainbows"        "ok_computer"        "kid_a"             
#>  [4] "the_king_of_limbs"  "amnesiac"           "hail_to_the_thief" 
#>  [7] "the_bends"          "pablo_honey"        "a_moon_shaped_pool"
#> [10] "the_white_album"

At the moment, we only have one non-Radiohead artist / album in the package, but more to come!

gapminder::gapminder %>%
  ggplot(aes(lifeExp, fill =  continent)) +
  geom_histogram(show.legend = TRUE, color = "black") +
  scale_fill_album_d(album = "the_white_album") +
  theme_minimal() + 
  theme_dark()
#> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

Non-ggplot2 use

I’ve built this package mostly around ggplot2 users, but base plot users can use it too.

You can use the ggroove::album function to generate a color palette based on your LP choice.

continuous_pal <- album_pal(256, lp = "kid_a")
image(volcano, col = continuous_pal)

discrete_pal <- album_pal(6, lp = "a_moon_shaped_pool")

boxplot(count ~ spray, data = InsectSprays, col = discrete_pal)

Credits

Code and concept for this package was adapted from the amazing fishualize and wesanderson packages.

ggroove's People

Contributors

danovando avatar

Watchers

James Cloos avatar  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.