Browse Source

coord_equal optional and nulled margins

pull/25/head
Bob Rudis 9 years ago
parent
commit
4dd9f6729a
  1. 5
      DESCRIPTION
  2. 1
      NAMESPACE
  3. 2
      R/waffle-package.R
  4. 25
      R/waffle.R
  5. 25
      README.Rmd
  6. 29
      README.md
  7. BIN
      README_files/figure-markdown_github/unnamed-chunk-3-1.png
  8. BIN
      README_files/figure-markdown_github/unnamed-chunk-3-2.png
  9. BIN
      README_files/figure-markdown_github/unnamed-chunk-3-3.png
  10. BIN
      README_files/figure-markdown_github/unnamed-chunk-3-4.png
  11. BIN
      README_files/figure-markdown_github/unnamed-chunk-3-5.png
  12. BIN
      README_files/figure-markdown_github/unnamed-chunk-4-1.png
  13. BIN
      README_files/figure-markdown_github/unnamed-chunk-6-1.png
  14. BIN
      README_files/figure-markdown_github/unnamed-chunk-7-1.png
  15. 6
      man/waffle.Rd

5
DESCRIPTION

@ -1,7 +1,7 @@
Package: waffle
Type: Package
Title: Create waffle charts (square pie charts)
Version: 0.2.1
Version: 0.2.3
Date: 2015-03-18
Author: Bob Rudis (@hrbrmstr)
Maintainer: Bob Rudis <bob@rudis.net>
@ -17,4 +17,5 @@ License: MIT + file LICENSE
Imports:
RColorBrewer,
pipeR,
htmlwidgets
htmlwidgets,
grid

1
NAMESPACE

@ -4,5 +4,6 @@ export(as_rcdimple)
export(waffle)
import(RColorBrewer)
import(ggplot2)
import(grid)
importFrom(htmlwidgets,JS)
importFrom(pipeR,"%>>%")

2
R/waffle-package.R

@ -2,7 +2,7 @@
#' @name waffle
#' @docType package
#' @author Bob Rudis (@@hrbrmstr)
#' @import ggplot2 RColorBrewer
#' @import ggplot2 RColorBrewer grid
#' @importFrom htmlwidgets JS
#' @importFrom pipeR %>>%
NULL

25
R/waffle.R

@ -25,6 +25,9 @@ y <- x <- value <- NULL
#' @param size width of the separator between blocks (defaults to \code{2})
#' @param flip flips x & y axes
#' @param reverse reverses the order of the data
#' @param equal by default, waffle uses \code{coord_equal}; this can cause layout problems,
#' so you an use this to disable it if you are using ggsave or knitr to control
#' output sizes (or manually sizing the chart)
#'
#' @examples \dontrun{
#' parts <- c(80, 30, 20, 10)
@ -56,7 +59,7 @@ y <- x <- value <- NULL
#'
#' @export
waffle <- function(parts, rows=10, xlab=NULL, title=NULL, colors=NA,
size=2, flip=FALSE, reverse=FALSE) {
size=2, flip=FALSE, reverse=FALSE, equal=TRUE) {
# fill in any missing names
@ -96,23 +99,37 @@ waffle <- function(parts, rows=10, xlab=NULL, title=NULL, colors=NA,
# make the plot
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()
if (equal) { 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(panel.background=element_blank())
gg <- gg + theme(panel.margin=unit(0, "null"))
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(axis.line=element_blank())
gg <- gg + theme(axis.ticks.length=unit(0, "null"))
gg <- gg + theme(axis.ticks.margin=unit(0, "null"))
gg <- gg + theme(plot.title=element_text(size=18))
gg <- gg + theme(plot.background=element_blank())
gg <- gg + theme(plot.margin=unit(c(0, 0, 0, 0), "null"))
gg <- gg + theme(plot.margin=rep(unit(0, "null"), 4))
gg
}

25
README.Rmd

@ -23,6 +23,7 @@ The following functions are implemented:
- Version `0.1` released
- Version `0.2` released - added `as_rcdimple` thx to Kent Russell
- Version `0.2.1` released - added Travis tests to ensure independent package build confirmation
- Version `0.2.3` released - nulled many margins and made the use of `coord_equal` optional via the `equal` parameter
### Installation
@ -55,21 +56,35 @@ 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")
**Health records breaches as a fraction os US popualation**
```{r}
waffle(parts/10, rows=3, colors=c("#969696", "#1879bf", "#009bda"))
```
<smaller>(One square == 10m ppl)</smaller>
```{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)
```
*Average Household Savings Each Year**
```{r}
waffle(savings/392, rows=7, size=0.5,
colors=c("#c7d4b6", "#a3aabd", "#a0d0de", "#97b5cf"),
title="Average Household Savings Each Year", xlab="1 square == $392")
colors=c("#c7d4b6", "#a3aabd", "#a0d0de", "#97b5cf"))
```
<smaller> (1 square == $392)</smaller>
```{r fig.height=3, fig.width=3}
# similar to but not exact
# https://eagereyes.org/techniques/square-pie-charts

29
README.md

@ -14,6 +14,7 @@ The following functions are implemented:
- Version `0.1` released
- Version `0.2` released - added `as_rcdimple` thx to Kent Russell
- Version `0.2.1` released - added Travis tests to ensure independent package build confirmation
- Version `0.2.3` released - nulled many margins and made the use of `coord_equal` optional via the `equal` parameter
### Installation
@ -35,7 +36,7 @@ library(waffle)
packageVersion("waffle")
```
## [1] '0.2.1'
## [1] '0.2.3'
``` r
# basic example
@ -58,13 +59,15 @@ waffle(parts, rows=8, size=1, colors=c("#969696", "#1879bf", "#009bda"),
![](README_files/figure-markdown_github/unnamed-chunk-3-2.png)
**Health records breaches as a fraction os US popualation**
``` 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")
waffle(parts/10, rows=3, colors=c("#969696", "#1879bf", "#009bda"))
```
![](README_files/figure-markdown_github/unnamed-chunk-3-3.png)
![](README_files/figure-markdown_github/unnamed-chunk-4-1.png)
<smaller>(One square == 10m ppl)</smaller>
``` r
# replicating an old favourite
@ -73,12 +76,18 @@ waffle(parts/10, rows=3, colors=c("#969696", "#1879bf", "#009bda"),
# 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)
```
\*Average Household Savings Each Year\*\*
``` r
waffle(savings/392, rows=7, size=0.5,
colors=c("#c7d4b6", "#a3aabd", "#a0d0de", "#97b5cf"),
title="Average Household Savings Each Year", xlab="1 square == $392")
colors=c("#c7d4b6", "#a3aabd", "#a0d0de", "#97b5cf"))
```
![](README_files/figure-markdown_github/unnamed-chunk-3-4.png)
![](README_files/figure-markdown_github/unnamed-chunk-6-1.png)
<smaller> (1 square == $392)</smaller>
``` r
# similar to but not exact
@ -89,7 +98,7 @@ 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)
![](README_files/figure-markdown_github/unnamed-chunk-7-1.png)
### Test Results
@ -100,7 +109,7 @@ library(testthat)
date()
```
## [1] "Thu Mar 19 07:27:54 2015"
## [1] "Thu Mar 19 11:29:53 2015"
``` r
test_dir("tests/")

BIN
README_files/figure-markdown_github/unnamed-chunk-3-1.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 17 KiB

BIN
README_files/figure-markdown_github/unnamed-chunk-3-2.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

After

Width:  |  Height:  |  Size: 30 KiB

BIN
README_files/figure-markdown_github/unnamed-chunk-3-3.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

After

Width:  |  Height:  |  Size: 24 KiB

BIN
README_files/figure-markdown_github/unnamed-chunk-3-4.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 36 KiB

After

Width:  |  Height:  |  Size: 36 KiB

BIN
README_files/figure-markdown_github/unnamed-chunk-3-5.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 22 KiB

BIN
README_files/figure-markdown_github/unnamed-chunk-4-1.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

BIN
README_files/figure-markdown_github/unnamed-chunk-6-1.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

BIN
README_files/figure-markdown_github/unnamed-chunk-7-1.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

6
man/waffle.Rd

@ -7,7 +7,7 @@
\title{A package to make waffle charts (square pie charts)}
\usage{
waffle(parts, rows = 10, xlab = NULL, title = NULL, colors = NA,
size = 2, flip = FALSE, reverse = FALSE)
size = 2, flip = FALSE, reverse = FALSE, equal = TRUE)
}
\arguments{
\item{parts}{[named] vector of values to use for the chart}
@ -27,6 +27,10 @@ Color Brewer "Set2" colors are used.}
\item{flip}{flips x & y axes}
\item{reverse}{reverses the order of the data}
\item{equal}{by default, waffle uses \code{coord_equal}; this can cause layout problems,
so you an use this to disable it if you are using ggsave or knitr to control
output sizes (or manually sizing the chart)}
}
\description{
A package to make waffle charts (square pie charts)

Loading…
Cancel
Save