Git Product home page Git Product logo

waffle's Introduction

Build Status CRAN_Status_Badge downloads

waffle is a package to make waffle charts (square pie charts)

It uses ggplot2 and returns a ggplot2 object.

The following functions are implemented:

  • waffle : make a waffle chart ggplot2 object
  • iron : vertically stitch together multiple waffle plots, left-aligning edges (best if used with the waffle pad parameter)

Installation

install.packages("waffle")

Usage

library(waffle)

# current verison
packageVersion("waffle")
## [1] '0.8.0'

Basic example

parts <- c(80, 30, 20, 10)
waffle(parts, rows=8)

Use a data frame

parts <- data.frame(
  names = LETTERS[1:4],
  vals = c(80, 30, 20, 10)
)

waffle(parts, rows=8)

Slightly more complex example

parts <- c(`Un-breached\nUS Population`=(318-11-79), `Premera`=11, `Anthem`=79)
waffle(parts, rows=8, size=1, colors=c("#969696", "#1879bf", "#009bda"), legend_pos="bottom") 

Health records breaches as fraction of US Population

One square == 1m ppl

waffle(parts/10, rows=3, colors=c("#969696", "#1879bf", "#009bda")) 

Health records breaches as fraction of US Population

(One square == 10m ppl)

library(extrafont)
waffle(parts/10, rows=3, colors=c("#969696", "#1879bf", "#009bda"),
       use_glyph="medkit", size=8)

Replicating an old favourite

Via: http://www.nytimes.com/2008/07/20/business/20debt.html

savings <- c(`Mortgage\n($84,911)`=84911, `Auto and\ntuition loans\n($14,414)`=14414, 
             `Home equity loans\n($10,062)`=10062, `Credit Cards\n($8,565)`=8565)
waffle(savings/392, rows=7, size=0.5, legend_pos="bottom",
       colors=c("#c7d4b6", "#a3aabd", "#a0d0de", "#97b5cf"))

Average Household Savings Each Year

(1 square == $392)

More replication

Similar to https://eagereyes.org/techniques/square-pie-charts

professional <- c(`Male`=44, `Female (56%)`=56)
waffle(professional, rows=10, size=0.5, colors=c("#af9139", "#544616"))

Keeps factor by default levels now

With:

iron(
  waffle(c(thing1=0, thing2=100), rows=5),  
  waffle(c(thing1=25, thing2=75), rows=5)
)

Without (you can disable this via keep parameter now):

iron(
  waffle(c(thing1=0, thing2=100), rows=5, keep=FALSE),  
  waffle(c(thing1=25, thing2=75), rows=5, keep=FALSE)
)

Professional Workforce Makeup

Iron example (left-align & padding for multiple plots)

pain.adult.1997 <- c(`YOY (406)`=406, `Adult (24)`=24)

A <- waffle(pain.adult.1997/2, rows=7, size=0.5, 
            colors=c("#c7d4b6", "#a3aabd"), 
            title="Paine Run Brook Trout Abundance (1997)", 
            xlab="1 square = 2 fish", pad=3)

pine.adult.1997 <- c(`YOY (221)`=221, `Adult (143)`=143)

B <- waffle(pine.adult.1997/2, rows=7, size=0.5, 
            colors=c("#c7d4b6", "#a3aabd"), 
            title="Piney River Brook Trout Abundance (1997)", 
            xlab="1 square = 2 fish", pad=8)

stan.adult.1997 <- c(`YOY (270)`=270, `Adult (197)`=197)

C <- waffle(stan.adult.1997/2, rows=7, size=0.5, 
            colors=c("#c7d4b6", "#a3aabd"), 
            title="Staunton River Trout Abundance (1997)", 
            xlab="1 square = 2 fish")

iron(A, B, C)

Test Results

library(waffle)
library(testthat)

date()
## [1] "Fri Apr  7 06:59:41 2017"

test_dir("tests/")
## testthat results ========================================================================================================
## OK: 1 SKIPPED: 0 FAILED: 0
## 
## DONE ===================================================================================================================

waffle's People

Contributors

hrbrmstr avatar timelyportfolio avatar j450h1 avatar calbertsen avatar markedmondson1234 avatar sfirke 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.