hrbrmstr
9 years ago
commit
dfc0aa71b5
19 changed files with 342 additions and 0 deletions
@ -0,0 +1,4 @@ |
|||
^.*\.Rproj$ |
|||
^\.Rproj\.user$ |
|||
^\.travis\.yml$ |
|||
^.*md$ |
@ -0,0 +1,7 @@ |
|||
.Rproj.user |
|||
.Rhistory |
|||
.RData |
|||
.Rproj |
|||
src/*.o |
|||
src/*.so |
|||
src/*.dll |
@ -0,0 +1,23 @@ |
|||
language: c |
|||
|
|||
before_install: |
|||
- curl -OL http://raw.github.com/craigcitro/r-travis/master/scripts/travis-tool.sh |
|||
- chmod 755 ./travis-tool.sh |
|||
- ./travis-tool.sh bootstrap |
|||
|
|||
install: |
|||
- ./travis-tool.sh install_github plyr |
|||
- ./travis-tool.sh install_deps |
|||
|
|||
script: ./travis-tool.sh run_tests |
|||
|
|||
on_failure: |
|||
- ./travis-tool.sh dump_logs |
|||
|
|||
branches: |
|||
except: |
|||
- /-expt$/ |
|||
notifications: |
|||
email: |
|||
on_success: change |
|||
on_failure: change |
@ -0,0 +1,18 @@ |
|||
Package: waffle |
|||
Type: Package |
|||
Title: Create waffle charts (square pie charts) |
|||
Version: 1.0 |
|||
Date: 2015-03-18 |
|||
Author: Bob Rudis (@hrbrmstr) |
|||
Maintainer: Bob Rudis <bob@rudis.net> |
|||
Description: Create waffle charts (square pie charts) |
|||
URL: http://github.com/hrbrmstr/waffle |
|||
BugReports: https://github.com/hrbrmstr/waffle/issues |
|||
License: MIT + file LICENSE |
|||
Suggests: |
|||
testthat |
|||
Depends: |
|||
R (>= 3.0.0), |
|||
ggplot2 |
|||
Imports: |
|||
RColorBrewer |
@ -0,0 +1,2 @@ |
|||
YEAR: 2015 |
|||
COPYRIGHT HOLDER: Bob Rudis |
@ -0,0 +1,5 @@ |
|||
# Generated by roxygen2 (4.1.0.9000): do not edit by hand |
|||
|
|||
export(waffle) |
|||
import(RColorBrewer) |
|||
import(ggplot2) |
@ -0,0 +1,6 @@ |
|||
#' A package to make waffle charts (square pie charts) |
|||
#' @name waffle |
|||
#' @docType package |
|||
#' @author Bob Rudis (@@hrbrmstr) |
|||
#' @import ggplot2 RColorBrewer |
|||
NULL |
@ -0,0 +1,52 @@ |
|||
#' @export |
|||
waffle <- function(parts, rows=10, xlab=NULL, title=NULL, colors=NA, size=2, flip=FALSE, reverse=FALSE) { |
|||
|
|||
require(ggplot2) |
|||
require(RColorBrewer) |
|||
|
|||
part_names <- names(parts) |
|||
if (length(part_names) < length(parts)) { |
|||
part_names <- c(part_names, LETTERS[1:length(parts)-length(part_names)]) |
|||
} |
|||
|
|||
if (all(is.na(colors))) { |
|||
colors <- brewer.pal(length(parts), "Set2") |
|||
} |
|||
|
|||
parts_vec <- unlist(sapply(1:length(parts), function(i) { |
|||
rep(LETTERS[i+1], parts[i]) |
|||
})) |
|||
|
|||
if (reverse) { parts_vec <- rev(parts_vec) } |
|||
|
|||
dat <- expand.grid(y=1:rows, x=seq_len(ceiling(sum(parts) / rows))) |
|||
|
|||
dat$value <- c(parts_vec, rep(NA, nrow(dat)-length(parts_vec))) |
|||
|
|||
if (flip) { |
|||
gg <- ggplot(dat, aes(x=y, y=x, fill=value)) |
|||
} else { |
|||
gg <- ggplot(dat, aes(x=x, y=y, fill=value)) |
|||
} |
|||
|
|||
gg <- gg + geom_tile(color="white", size=size) |
|||
gg <- gg + coord_equal() |
|||
gg <- gg + labs(x=xlab, y=NULL, title=title) |
|||
gg <- gg + scale_x_continuous(expand=c(0, 0)) |
|||
gg <- gg + scale_y_continuous(expand=c(0, 0)) |
|||
gg <- gg + scale_fill_manual(name="", |
|||
values=colors, |
|||
labels=part_names) |
|||
gg <- gg + guides(fill=guide_legend(override.aes=list(colour=NULL))) |
|||
gg <- gg + coord_equal() |
|||
gg <- gg + theme_bw() |
|||
gg <- gg + theme(panel.grid=element_blank()) |
|||
gg <- gg + theme(panel.border=element_blank()) |
|||
gg <- gg + theme(axis.text=element_blank()) |
|||
gg <- gg + theme(axis.title.x=element_text(size=10)) |
|||
gg <- gg + theme(axis.ticks=element_blank()) |
|||
gg <- gg + theme(plot.title=element_text(size=18)) |
|||
|
|||
gg |
|||
|
|||
} |
@ -0,0 +1,81 @@ |
|||
--- |
|||
title: "README" |
|||
author: "Bob Rudis" |
|||
date: March 18, 2015 |
|||
output: |
|||
md_document: |
|||
variant: markdown_github |
|||
--- |
|||
|
|||
waffle is a packae to make waffle charts (square pie charts) |
|||
|
|||
It uses ggplot2 and returns a ggplot2 object. |
|||
|
|||
The following functions are implemented: |
|||
|
|||
- `waffle` |
|||
|
|||
### News |
|||
|
|||
- Version `0.1` released |
|||
|
|||
### Installation |
|||
|
|||
```{r eval=FALSE} |
|||
devtools::install_github("hrbrmstr/waffle") |
|||
``` |
|||
|
|||
```{r echo=FALSE, message=FALSE, warning=FALSE, error=FALSE} |
|||
options(width=120) |
|||
``` |
|||
|
|||
### Usage |
|||
|
|||
```{r} |
|||
library(waffle) |
|||
|
|||
# current verison |
|||
packageVersion("waffle") |
|||
|
|||
# basic example |
|||
|
|||
parts <- 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"), |
|||
title="Health records breaches as fraction of US Population", |
|||
xlab="One square == 1m ppl") |
|||
|
|||
waffle(parts/10, rows=3, colors=c("#969696", "#1879bf", "#009bda"), |
|||
title="Health records breaches as fraction of US Population", |
|||
xlab="One square == 10m ppl") |
|||
|
|||
# replicating an old favourite |
|||
|
|||
# http://graphics8.nytimes.com/images/2008/07/20/business/20debtgraphic.jpg |
|||
# http://www.nytimes.com/2008/07/20/business/20debt.html |
|||
savings <- c(`Mortgage ($84,911)`=84911, `Auto and\ntuition loans ($14,414)`=14414, `Home equity loans ($10,062)`=10062, `Credit Cards ($8,565)`=8565) |
|||
waffle(savings/392, rows=7, size=0.5, colors=c("#c7d4b6", "#a3aabd", "#a0d0de", "#97b5cf"), title="Average Household Savings Each Year", xlab="1 square == $392") |
|||
|
|||
# similar to but not exact |
|||
|
|||
# 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"), title="Professional Workforce Makeup") |
|||
``` |
|||
|
|||
### Test Results |
|||
|
|||
```{r} |
|||
library(waffle) |
|||
library(testthat) |
|||
|
|||
date() |
|||
|
|||
test_dir("tests/") |
|||
``` |
|||
|
@ -0,0 +1,101 @@ |
|||
waffle is a packae to make waffle charts (square pie charts) |
|||
|
|||
It uses ggplot2 and returns a ggplot2 object. |
|||
|
|||
The following functions are implemented: |
|||
|
|||
- `waffle` |
|||
|
|||
### News |
|||
|
|||
- Version `0.1` released |
|||
|
|||
### Installation |
|||
|
|||
``` r |
|||
devtools::install_github("hrbrmstr/waffle") |
|||
``` |
|||
|
|||
### Usage |
|||
|
|||
``` r |
|||
library(waffle) |
|||
``` |
|||
|
|||
## Loading required package: ggplot2 |
|||
|
|||
``` r |
|||
# current verison |
|||
packageVersion("waffle") |
|||
``` |
|||
|
|||
## [1] '1.0' |
|||
|
|||
``` r |
|||
# basic example |
|||
|
|||
parts <- c(80, 30, 20, 10) |
|||
waffle(parts, rows=8) |
|||
``` |
|||
|
|||
## Loading required package: RColorBrewer |
|||
|
|||
![](README_files/figure-markdown_github/unnamed-chunk-3-1.png) |
|||
|
|||
``` r |
|||
# 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"), |
|||
title="Health records breaches as fraction of US Population", |
|||
xlab="One square == 1m ppl") |
|||
``` |
|||
|
|||
![](README_files/figure-markdown_github/unnamed-chunk-3-2.png) |
|||
|
|||
``` r |
|||
waffle(parts/10, rows=3, colors=c("#969696", "#1879bf", "#009bda"), |
|||
title="Health records breaches as fraction of US Population", |
|||
xlab="One square == 10m ppl") |
|||
``` |
|||
|
|||
![](README_files/figure-markdown_github/unnamed-chunk-3-3.png) |
|||
|
|||
``` r |
|||
# replicating an old favourite |
|||
|
|||
# http://graphics8.nytimes.com/images/2008/07/20/business/20debtgraphic.jpg |
|||
# http://www.nytimes.com/2008/07/20/business/20debt.html |
|||
savings <- c(`Mortgage ($84,911)`=84911, `Auto and\ntuition loans ($14,414)`=14414, `Home equity loans ($10,062)`=10062, `Credit Cards ($8,565)`=8565) |
|||
waffle(savings/392, rows=7, size=0.5, colors=c("#c7d4b6", "#a3aabd", "#a0d0de", "#97b5cf"), title="Average Household Savings Each Year", xlab="1 square == $392") |
|||
``` |
|||
|
|||
![](README_files/figure-markdown_github/unnamed-chunk-3-4.png) |
|||
|
|||
``` r |
|||
# similar to but not exact |
|||
|
|||
# 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"), title="Professional Workforce Makeup") |
|||
``` |
|||
|
|||
![](README_files/figure-markdown_github/unnamed-chunk-3-5.png) |
|||
|
|||
### Test Results |
|||
|
|||
``` r |
|||
library(waffle) |
|||
library(testthat) |
|||
|
|||
date() |
|||
``` |
|||
|
|||
## [1] "Wed Mar 18 15:46:55 2015" |
|||
|
|||
``` r |
|||
test_dir("tests/") |
|||
``` |
|||
|
|||
## basic functionality : |
After Width: | Height: | Size: 18 KiB |
After Width: | Height: | Size: 31 KiB |
After Width: | Height: | Size: 24 KiB |
After Width: | Height: | Size: 36 KiB |
After Width: | Height: | Size: 20 KiB |
@ -0,0 +1,14 @@ |
|||
% Generated by roxygen2 (4.1.0.9000): do not edit by hand |
|||
% Please edit documentation in R/waffle-package.R |
|||
\docType{package} |
|||
\name{waffle} |
|||
\alias{waffle} |
|||
\alias{waffle-package} |
|||
\title{A package to make waffle charts (square pie charts)} |
|||
\description{ |
|||
A package to make waffle charts (square pie charts) |
|||
} |
|||
\author{ |
|||
Bob Rudis (@hrbrmstr) |
|||
} |
|||
|
@ -0,0 +1,2 @@ |
|||
library(testthat) |
|||
test_check("waffle") |
@ -0,0 +1,6 @@ |
|||
context("basic functionality") |
|||
test_that("we can do something", { |
|||
|
|||
#expect_that(some_function(), is_a("data.frame")) |
|||
|
|||
}) |
@ -0,0 +1,21 @@ |
|||
Version: 1.0 |
|||
|
|||
RestoreWorkspace: Default |
|||
SaveWorkspace: Default |
|||
AlwaysSaveHistory: Default |
|||
|
|||
EnableCodeIndexing: Yes |
|||
UseSpacesForTab: Yes |
|||
NumSpacesForTab: 2 |
|||
Encoding: UTF-8 |
|||
|
|||
RnwWeave: Sweave |
|||
LaTeX: pdfLaTeX |
|||
|
|||
StripTrailingWhitespace: Yes |
|||
|
|||
BuildType: Package |
|||
PackageUseDevtools: Yes |
|||
PackageInstallArgs: --no-multiarch --with-keep.source |
|||
PackageBuildArgs: --resave-data |
|||
PackageRoxygenize: rd,collate,namespace |
Loading…
Reference in new issue