diff --git a/.travis.yml b/.travis.yml index a7fe972..781fc47 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,24 +1,18 @@ -language: c +language: r +r: + - oldrel + - release + - devel +warnings_are_errors: true +cache: packages +r_check_revdep: false sudo: required -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 +env: + global: + - CRAN: http://cran.rstudio.com -install: - - ./travis-tool.sh r_binary_install RColorBrewer - - ./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 +notifications: + email: + on_success: change + on_failure: change \ No newline at end of file diff --git a/DESCRIPTION b/DESCRIPTION index 56c9b0c..7f72d21 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,9 +1,12 @@ Package: waffle Type: Package Title: Create Waffle Chart Visualizations in R -Version: 0.6.0 -Date: 2016-09-18 -Author: Bob Rudis , Dave Gandy (FontAwesome) +Version: 0.7.0 +Date: 2017-01-07 +Authors@R: c( + person("Bob", "Rudis", email = "bob@rud.is", role = c("aut", "cre")), + person("Dave", "Gandy", role = "aut", comment = "Font Awesome") + ) Maintainer: Bob Rudis Description: Square pie charts (a.k.a. waffle charts) can be used to communicate parts of a whole for categorical quantities. To emulate the @@ -19,8 +22,8 @@ BugReports: https://github.com/hrbrmstr/waffle/issues Suggests: testthat Depends: - R (>= 3.1.0), - ggplot2 (>= 1.0.1) + R (>= 3.2.0), + ggplot2 (>= 2.0.0) License: GPL (>= 2) Imports: RColorBrewer, diff --git a/NEWS.md b/NEWS.md new file mode 100644 index 0000000..249992b --- /dev/null +++ b/NEWS.md @@ -0,0 +1,33 @@ +### News + +waffle 0.7.0 +- yet more fixes for latest ggplot2 2.x +- made factor-level keeping a parameter (TRUE by default) + +waffle 0.6.0 +- keep factor levels; improve default aesthetics + +waffle 0.5.1 +- even moar improved ggplot2 compatibility + +waffle 0.5 +- new & improved ggplot2 compatibility + +waffle 0.4 +- added `use_glyph()` and `glyph_size()` to `waffle()` so you can now make isotype pictograms + +waffle 0.3 +- added a `pad parameter to `waffle to make it easier to align plots +- added `iron to make it easier to do the alignment + +waffle 0.2.3 +- nulled many margins and made the use of `coord_equal optional via the `equal parameter + +waffle 0.2.1 +- added Travis tests to ensure independent package build confirmation + +waffle 0.2 +- added `as_rcdimple thx to Kent Russell (only in non-CRAN version) + +waffle 0.1 +- initial release diff --git a/R/aaa.r b/R/aaa.r new file mode 100644 index 0000000..3b656ae --- /dev/null +++ b/R/aaa.r @@ -0,0 +1 @@ +utils::globalVariables(c("x", "y", "value")) \ No newline at end of file diff --git a/R/iron.R b/R/iron.R index 0fb8e4b..0540e33 100644 --- a/R/iron.R +++ b/R/iron.R @@ -1,68 +1,3 @@ -# VIA: http://stackoverflow.com/q/13294952/1457051 - -rbind_gtable_max <- function(...) { - - gtl <- list(...) - stopifnot(all(sapply(gtl, is.gtable))) - bind2 <- function (x, y) { - stopifnot(ncol(x) == ncol(y)) - if (nrow(x) == 0) - return(y) - if (nrow(y) == 0) - return(x) - y$layout$t <- y$layout$t + nrow(x) - y$layout$b <- y$layout$b + nrow(x) - x$layout <- rbind(x$layout, y$layout) - x$heights <- insert_unit(x$heights, y$heights) - x$rownames <- c(x$rownames, y$rownames) - x$widths <- unit.pmax(x$widths, y$widths) - x$grobs <- append(x$grobs, y$grobs) - x - } - Reduce(bind2, gtl) - -} - -cbind_gtable_max <- function(...) { - - gtl <- list(...) - stopifnot(all(sapply(gtl, is.gtable))) - bind2 <- function (x, y) { - stopifnot(nrow(x) == nrow(y)) - if (ncol(x) == 0) - return(y) - if (ncol(y) == 0) - return(x) - y$layout$l <- y$layout$l + ncol(x) - y$layout$r <- y$layout$r + ncol(x) - x$layout <- rbind(x$layout, y$layout) - x$widths <- insert_unit(x$widths, y$widths) - x$colnames <- c(x$colnames, y$colnames) - x$heights <- unit.pmax(x$heights, y$heights) - x$grobs <- append(x$grobs, y$grobs) - x - } - Reduce(bind2, gtl) - -} - -insert_unit <- function (x, values, after = length(x)) { - lengx <- length(x) - if (lengx == 0) - return(values) - if (length(values) == 0) - return(x) - if (after <= 0) { - unit.c(values, x) - } - else if (after >= lengx) { - unit.c(x, values) - } - else { - unit.c(x[1L:after], values, x[(after + 1L):lengx]) - } -} - #' Veritical, left-aligned layout for waffle plots #' #' Left-align the waffle plots by x-axis. Use the \code{pad} parameter in @@ -76,8 +11,8 @@ insert_unit <- function (x, values, after = length(x)) { #' w1 <- waffle(parts, rows=8) #' w2 <- waffle(parts, rows=8) #' w3 <- waffle(parts, rows=8) -#' chart <- iron(w1, w2, w3) #' # print chart +#' ## iron(w1, w2, w3) iron <- function(...) { grob_list <- list(...) grid.newpage() diff --git a/R/utils.r b/R/utils.r new file mode 100644 index 0000000..a99ef25 --- /dev/null +++ b/R/utils.r @@ -0,0 +1,77 @@ +# VIA: http://stackoverflow.com/q/13294952/1457051 + +rbind_gtable_max <- function(...) { + + gtl <- list(...) + + stopifnot(all(sapply(gtl, is.gtable))) + + bind2 <- function (x, y) { + + stopifnot(ncol(x) == ncol(y)) + + if (nrow(x) == 0) return(y) + if (nrow(y) == 0) return(x) + + y$layout$t <- y$layout$t + nrow(x) + y$layout$b <- y$layout$b + nrow(x) + x$layout <- rbind(x$layout, y$layout) + + x$heights <- insert_unit(x$heights, y$heights) + x$rownames <- c(x$rownames, y$rownames) + x$widths <- unit.pmax(x$widths, y$widths) + x$grobs <- append(x$grobs, y$grobs) + + x + + } + Reduce(bind2, gtl) + +} + +cbind_gtable_max <- function(...) { + + gtl <- list(...) + + stopifnot(all(sapply(gtl, is.gtable))) + + bind2 <- function (x, y) { + + stopifnot(nrow(x) == nrow(y)) + + if (ncol(x) == 0) return(y) + if (ncol(y) == 0) return(x) + + y$layout$l <- y$layout$l + ncol(x) + y$layout$r <- y$layout$r + ncol(x) + x$layout <- rbind(x$layout, y$layout) + + x$widths <- insert_unit(x$widths, y$widths) + x$colnames <- c(x$colnames, y$colnames) + x$heights <- unit.pmax(x$heights, y$heights) + x$grobs <- append(x$grobs, y$grobs) + + x + + } + + Reduce(bind2, gtl) + +} + +insert_unit <- function (x, values, after = length(x)) { + + lengx <- length(x) + + if (lengx == 0) return(values) + if (length(values) == 0) return(x) + + if (after <= 0) { + unit.c(values, x) + } else if (after >= lengx) { + unit.c(x, values) + } else { + unit.c(x[1L:after], values, x[(after + 1L):lengx]) + } + +} diff --git a/R/waffle-package.R b/R/waffle-package.R index a3636d7..f6cda72 100644 --- a/R/waffle-package.R +++ b/R/waffle-package.R @@ -16,7 +16,5 @@ #' @importFrom ggplot2 scale_x_continuous scale_y_continuous coord_equal theme_bw #' @importFrom ggplot2 aes guide_legend element_rect element_blank element_text #' @importFrom grid arrow unit grid.newpage grid.draw unit.c unit.pmax unit.pmin -#' @importFrom extrafont ttf_import -#' @importFrom extrafont font_import -#' @importFrom extrafont choose_font +#' @importFrom extrafont ttf_import font_import choose_font NULL diff --git a/R/waffle.R b/R/waffle.R index aa26115..e09b2f8 100644 --- a/R/waffle.R +++ b/R/waffle.R @@ -1,5 +1,3 @@ -x <- y <- value <- NULL - #' Make waffle (square pie) charts #' #' Given a named vector, this function will return a ggplot object that @@ -29,6 +27,7 @@ x <- y <- value <- NULL #' #' @param parts named vector of values to use for the chart #' @param rows number of rows of blocks +#' @param keep keep factor levels (i.e. for consistent legends across waffle plots) #' @param xlab text for below the chart. Highly suggested this be used to #' give the "1 sq == xyz" relationship if it's not obvious #' @param title chart title @@ -56,7 +55,7 @@ x <- y <- value <- NULL #' parts <- c(One=80, Two=30, Three=20, Four=10) #' chart <- waffle(parts, rows=8) #' # print(chart) -waffle <- function(parts, rows=10, xlab=NULL, title=NULL, colors=NA, +waffle <- function(parts, rows=10, keep=TRUE, xlab=NULL, title=NULL, colors=NA, size=2, flip=FALSE, reverse=FALSE, equal=TRUE, pad=0, use_glyph=FALSE, glyph_size=12, legend_pos="right") { @@ -79,13 +78,14 @@ waffle <- function(parts, rows=10, xlab=NULL, title=NULL, colors=NA, if (reverse) parts_vec <- rev(parts_vec) # setup the data frame for geom_rect - dat <- expand.grid(y=1:rows, x=seq_len(pad + (ceiling(sum(parts) / rows)))) +dat <- expand.grid(y=1:rows, x=seq_len(pad + (ceiling(sum(parts) / rows)))) # add NAs if needed to fill in the "rectangle" dat$value <- c(parts_vec, rep(NA, nrow(dat)-length(parts_vec))) if(!inherits(use_glyph, "logical")){ fontlab <- rep(fa_unicode[use_glyph],length(unique(parts_vec))) - dat$fontlab <- c(fontlab[as.numeric(factor(parts_vec))], rep(NA, nrow(dat)-length(parts_vec))) + dat$fontlab <- c(fontlab[as.numeric(factor(parts_vec))], + rep(NA, nrow(dat)-length(parts_vec))) } dat$value <- ifelse(is.na(dat$value), " ", dat$value) @@ -95,11 +95,9 @@ waffle <- function(parts, rows=10, xlab=NULL, title=NULL, colors=NA, dat$value <- factor(dat$value, levels=part_names) - if (flip) { - gg <- ggplot(dat, aes(x=y, y=x)) - } else { - gg <- ggplot(dat, aes(x=x, y=y)) - } + gg <- ggplot(dat, aes(x=x, y=y)) + + if (flip) gg <- ggplot(dat, aes(x=y, y=x)) gg <- gg + theme_bw() @@ -112,7 +110,7 @@ waffle <- function(parts, rows=10, xlab=NULL, title=NULL, colors=NA, values=colors, label=part_names, na.value="white", - drop=TRUE) + drop=!keep) gg <- gg + guides(fill=guide_legend(override.aes=list(colour="#00000000"))) gg <- gg + theme(legend.background=element_rect(fill="#00000000", color="#00000000")) gg <- gg + theme(legend.key=element_rect(fill="#00000000", color="#00000000")) @@ -140,8 +138,8 @@ waffle <- function(parts, rows=10, xlab=NULL, title=NULL, colors=NA, family="FontAwesome", size=glyph_size, show.legend=FALSE) gg <- gg + scale_color_manual(name="", values=colors, - labels=ifelse(is.na(part_names), "", part_names), - drop=TRUE) + labels=part_names, + drop=!keep) gg <- gg + guides(color=guide_legend(override.aes=list(shape=15, size=7))) gg <- gg + theme(legend.background=element_rect(fill="#00000000", color="#00000000")) gg <- gg + theme(legend.key=element_rect(color="#00000000")) @@ -152,7 +150,7 @@ waffle <- function(parts, rows=10, xlab=NULL, title=NULL, colors=NA, gg <- gg + scale_x_continuous(expand=c(0, 0)) gg <- gg + scale_y_continuous(expand=c(0, 0)) - if (equal) { gg <- gg + coord_equal() } + if (equal) gg <- gg + coord_equal() gg <- gg + theme(panel.grid=element_blank()) gg <- gg + theme(panel.border=element_blank()) @@ -169,8 +167,9 @@ waffle <- function(parts, rows=10, xlab=NULL, title=NULL, colors=NA, gg <- gg + theme(plot.background=element_blank()) gg <- gg + theme(panel.spacing=unit(c(0, 0, 0, 0), "null")) - gg <- gg + theme(panel.spacing=rep(unit(0, "null"), 4)) gg <- gg + theme(legend.position=legend_pos) + gg + } diff --git a/README.Rmd b/README.Rmd index f1f7c5b..f562262 100644 --- a/README.Rmd +++ b/README.Rmd @@ -2,18 +2,13 @@ output: rmarkdown::github_document --- ```{r, include = FALSE} -knitr::opts_chunk$set( - collapse = TRUE, - message=FALSE, - fig.retina = 2 -) +knitr::opts_chunk$set(echo=TRUE, collapse=TRUE, message=FALSE, warning=FALSE, error=FALSE, fig.retina=2) ``` [![Build Status](https://travis-ci.org/hrbrmstr/waffle.svg)](https://travis-ci.org/hrbrmstr/waffle) -[![Project Status: Active - The project has reached a stable, usable state and is being actively developed.](http://www.repostatus.org/badges/0.1.0/active.svg)](http://www.repostatus.org/#active) [![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/waffle)](https://cran.r-project.org/package=waffle) ![downloads](http://cranlogs.r-pkg.org/badges/grand-total/waffle) -waffle is a package to make waffle charts (square pie charts) +`waffle` is a package to make waffle charts (square pie charts) It uses ggplot2 and returns a ggplot2 object. @@ -22,31 +17,19 @@ 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) -### News - -- Version `0.6.0` - keep factor levels; improve default aesthetics -- Version `0.5.1` released - even moar improved ggplot2 compatibility -- Version `0.5` released - new & improved ggplot2 compatibility -- Version `0.4` released - added `use_glyph` and `glyph_size` to `waffle` so you can now make isotype pictograms -- Version `0.3` released - added a `pad` parameter to `waffle` to make it easier to align plots; added `iron` to make it easier to do the alignment -- Version `0.2.3` released - nulled many margins and made the use of `coord_equal` optional via the `equal` parameter -- Version `0.2.1` released - added Travis tests to ensure independent package build confirmation -- Version `0.2` released - added `as_rcdimple` thx to Kent Russell (only in non-CRAN version) -- Version `0.1` released - ### Installation -```{r s1, eval=FALSE, message=FALSE, warning=FALSE} +```{r s1, eval=FALSE} install.packages("waffle") ``` -```{r s2, echo=FALSE, message=FALSE, warning=FALSE, error=FALSE} +```{r s2, include=FALSE} options(width=120) ``` ### Usage -```{r s3, message=FALSE, warning=FALSE} +```{r s3} library(waffle) # current verison @@ -56,7 +39,7 @@ packageVersion("waffle") parts <- c(80, 30, 20, 10) ``` -```{r fig1, fig.width=6, fig.height=2.5, message=FALSE, warning=FALSE} +```{r fig1, fig.width=6, fig.height=2.5} waffle(parts, rows=8) ``` @@ -65,37 +48,35 @@ waffle(parts, rows=8) parts <- c(`Un-breached\nUS Population`=(318-11-79), `Premera`=11, `Anthem`=79) ``` -```{r t1, eval=FALSE, message=FALSE, warning=FALSE, fig.width=6, fig.height=3} -waffle(parts, rows=8, size=1, colors=c("#969696", "#1879bf", "#009bda")) + - theme(legend.position="bottom") +```{r t1, eval=FALSE} +waffle(parts, rows=8, size=1, colors=c("#969696", "#1879bf", "#009bda"), legend_pos="bottom") ``` **Health records breaches as fraction of US Population** -```{r fig2, echo=FALSE, fig.width=6, fig.height=1.75, message=FALSE, warning=FALSE} -waffle(parts, rows=8, size=1, colors=c("#969696", "#1879bf", "#009bda")) + - theme(legend.position="bottom") +```{r fig2, echo=FALSE, fig.width=6, fig.height=1.75} +waffle(parts, rows=8, size=1, colors=c("#969696", "#1879bf", "#009bda"), legend_pos="bottom") ``` One square == 1m ppl -```{r t2, eval=FALSE, message=FALSE, warning=FALSE} +```{r t2, eval=FALSE} waffle(parts/10, rows=3, colors=c("#969696", "#1879bf", "#009bda")) ``` **Health records breaches as fraction of US Population** -```{r fig3, echo=FALSE, fig.width=6, fig.height=2, message=FALSE, warning=FALSE} +```{r fig3, echo=FALSE, fig.width=6, fig.height=2} waffle(parts/10, rows=3, colors=c("#969696", "#1879bf", "#009bda")) ``` (One square == 10m ppl) -```{r ww1, eval=FALSE, message=FALSE, warning=FALSE} +```{r ww1, eval=FALSE} library(extrafont) waffle(parts/10, rows=3, colors=c("#969696", "#1879bf", "#009bda"), use_glyph="medkit", size=8) ``` -```{r ww2, echo=FALSE, fig.width=6, fig.height=2, message=FALSE, warning=FALSE} +```{r ww2, echo=FALSE, fig.width=6, fig.height=2} library(extrafont) waffle(parts/10, rows=3, colors=c("#969696", "#1879bf", "#009bda"), use_glyph="medkit", glyph_size=8) @@ -107,21 +88,19 @@ waffle(parts/10, rows=3, colors=c("#969696", "#1879bf", "#009bda"), # http://graphics8.nytimes.com/images/2008/07/20/business/20debtgraphic.jpg # 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) + `Home equity loans\n($10,062)`=10062, `Credit Cards\n($8,565)`=8565) ``` ```{r fig4, eval=FALSE} -waffle(savings/392, rows=7, size=0.5, - colors=c("#c7d4b6", "#a3aabd", "#a0d0de", "#97b5cf")) + - theme(legend.position="bottom") +waffle(savings/392, rows=7, size=0.5, legend_pos="bottom", + colors=c("#c7d4b6", "#a3aabd", "#a0d0de", "#97b5cf")) ``` **Average Household Savings Each Year** -```{r fig4a, echo=FALSE, fig.width=8, fig.height=2.5, message=FALSE, warning=FALSE} -waffle(savings/392, rows=7, size=0.5, - colors=c("#c7d4b6", "#a3aabd", "#a0d0de", "#97b5cf")) + - theme(legend.position="bottom") +```{r fig4a, echo=FALSE, fig.width=8, fig.height=2.5} +waffle(savings/392, rows=7, size=0.5, legend_pos="bottom", + colors=c("#c7d4b6", "#a3aabd", "#a0d0de", "#97b5cf")) ``` (1 square == $392) @@ -133,47 +112,59 @@ waffle(savings/392, rows=7, size=0.5, professional <- c(`Male`=44, `Female (56%)`=56) ``` -```{r t5, eval=FALSE, message=FALSE, warning=FALSE} +```{r t5, eval=FALSE} waffle(professional, rows=10, size=0.5, colors=c("#af9139", "#544616")) ``` -### Keeps factor levels now +### Keeps factor by default levels now -```{r fct, fig.height=3, fig.width=6, message=FALSE, warning=FALSE} -gridExtra::grid.arrange( +With: + +```{r fct, fig.height=3, fig.width=6} +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): + +```{r no_fct, fig.height=3, fig.width=6} +iron( + waffle(c(thing1=0, thing2=100), rows=5, keep=FALSE), + waffle(c(thing1=25, thing2=75), rows=5, keep=FALSE) +) +``` **Professional Workforce Makeup** -```{r f5, echo=FALSE, fig.height=3, fig.width=4, message=FALSE, warning=FALSE} +```{r f5, echo=FALSE, fig.height=3, fig.width=4} waffle(professional, rows=10, size=0.5, colors=c("#af9139", "#544616")) ``` Iron example (left-align & padding for multiple plots) -```{r f8, fig.height=6, fig.width=7, message=FALSE, warning=FALSE} -pain.adult.1997 <- c( `YOY (406)`=406, `Adult (24)`=24) +```{r f8, fig.height=6, fig.width=7} +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) + 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) -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) + 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") +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) ``` diff --git a/README.md b/README.md index c66be6b..4b30b1e 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ -[![Build Status](https://travis-ci.org/hrbrmstr/waffle.svg)](https://travis-ci.org/hrbrmstr/waffle) [![Project Status: Active - The project has reached a stable, usable state and is being actively developed.](http://www.repostatus.org/badges/0.1.0/active.svg)](http://www.repostatus.org/#active) [![CRAN\_Status\_Badge](http://www.r-pkg.org/badges/version/waffle)](https://cran.r-project.org/package=waffle) ![downloads](http://cranlogs.r-pkg.org/badges/grand-total/waffle) +[![Build Status](https://travis-ci.org/hrbrmstr/waffle.svg)](https://travis-ci.org/hrbrmstr/waffle) [![CRAN\_Status\_Badge](http://www.r-pkg.org/badges/version/waffle)](https://cran.r-project.org/package=waffle) ![downloads](http://cranlogs.r-pkg.org/badges/grand-total/waffle) -waffle is a package to make waffle charts (square pie charts) +`waffle` is a package to make waffle charts (square pie charts) It uses ggplot2 and returns a ggplot2 object. @@ -10,18 +10,6 @@ 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) -### News - -- Version `0.6.0` - keep factor levels; improve default aesthetics -- Version `0.5.1` released - even moar improved ggplot2 compatibility -- Version `0.5` released - new & improved ggplot2 compatibility -- Version `0.4` released - added `use_glyph` and `glyph_size` to `waffle` so you can now make isotype pictograms -- Version `0.3` released - added a `pad` parameter to `waffle` to make it easier to align plots; added `iron` to make it easier to do the alignment -- Version `0.2.3` released - nulled many margins and made the use of `coord_equal` optional via the `equal` parameter -- Version `0.2.1` released - added Travis tests to ensure independent package build confirmation -- Version `0.2` released - added `as_rcdimple` thx to Kent Russell (only in non-CRAN version) -- Version `0.1` released - ### Installation ``` r @@ -35,7 +23,7 @@ library(waffle) # current verison packageVersion("waffle") -## [1] '0.6.0' +## [1] '0.7.0' # basic example parts <- c(80, 30, 20, 10) @@ -53,8 +41,7 @@ parts <- c(`Un-breached\nUS Population`=(318-11-79), `Premera`=11, `Anthem`=79) ``` ``` r -waffle(parts, rows=8, size=1, colors=c("#969696", "#1879bf", "#009bda")) + - theme(legend.position="bottom") +waffle(parts, rows=8, size=1, colors=c("#969696", "#1879bf", "#009bda"), legend_pos="bottom") ``` **Health records breaches as fraction of US Population** @@ -83,13 +70,12 @@ waffle(parts/10, rows=3, colors=c("#969696", "#1879bf", "#009bda"), # http://graphics8.nytimes.com/images/2008/07/20/business/20debtgraphic.jpg # 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) + `Home equity loans\n($10,062)`=10062, `Credit Cards\n($8,565)`=8565) ``` ``` r -waffle(savings/392, rows=7, size=0.5, - colors=c("#c7d4b6", "#a3aabd", "#a0d0de", "#97b5cf")) + - theme(legend.position="bottom") +waffle(savings/392, rows=7, size=0.5, legend_pos="bottom", + colors=c("#c7d4b6", "#a3aabd", "#a0d0de", "#97b5cf")) ``` **Average Household Savings Each Year** @@ -107,10 +93,12 @@ professional <- c(`Male`=44, `Female (56%)`=56) waffle(professional, rows=10, size=0.5, colors=c("#af9139", "#544616")) ``` -### Keeps factor levels now +### Keeps factor by default levels now + +With: ``` r -gridExtra::grid.arrange( +iron( waffle(c(thing1=0, thing2=100), rows=5), waffle(c(thing1=25, thing2=75), rows=5) ) @@ -118,6 +106,17 @@ gridExtra::grid.arrange( +Without (you can disable this via `keep` parameter now): + +``` r +iron( + waffle(c(thing1=0, thing2=100), rows=5, keep=FALSE), + waffle(c(thing1=25, thing2=75), rows=5, keep=FALSE) +) +``` + + + **Professional Workforce Makeup** @@ -125,24 +124,26 @@ gridExtra::grid.arrange( Iron example (left-align & padding for multiple plots) ``` r -pain.adult.1997 <- c( `YOY (406)`=406, `Adult (24)`=24) +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) + 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) -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) + 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") +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) ``` @@ -156,12 +157,11 @@ library(waffle) library(testthat) date() -## [1] "Fri Jan 6 17:32:46 2017" +## [1] "Sat Jan 7 08:05:00 2017" test_dir("tests/") ## testthat results ======================================================================================================== ## OK: 1 SKIPPED: 0 FAILED: 0 ## ## DONE =================================================================================================================== -## You rock! ``` diff --git a/README_files/figure-markdown_github/f8-1.png b/README_files/figure-markdown_github/f8-1.png index b58efc1..6aaf9f5 100644 Binary files a/README_files/figure-markdown_github/f8-1.png and b/README_files/figure-markdown_github/f8-1.png differ diff --git a/README_files/figure-markdown_github/fct-1.png b/README_files/figure-markdown_github/fct-1.png index ce0fafc..68a0b9d 100644 Binary files a/README_files/figure-markdown_github/fct-1.png and b/README_files/figure-markdown_github/fct-1.png differ diff --git a/README_files/figure-markdown_github/fig1-1.png b/README_files/figure-markdown_github/fig1-1.png index f1ecd52..dda4d0f 100644 Binary files a/README_files/figure-markdown_github/fig1-1.png and b/README_files/figure-markdown_github/fig1-1.png differ diff --git a/README_files/figure-markdown_github/fig2-1.png b/README_files/figure-markdown_github/fig2-1.png index 909cf57..07766a9 100644 Binary files a/README_files/figure-markdown_github/fig2-1.png and b/README_files/figure-markdown_github/fig2-1.png differ diff --git a/README_files/figure-markdown_github/fig3-1.png b/README_files/figure-markdown_github/fig3-1.png index ba17750..b574525 100644 Binary files a/README_files/figure-markdown_github/fig3-1.png and b/README_files/figure-markdown_github/fig3-1.png differ diff --git a/README_files/figure-markdown_github/fig4a-1.png b/README_files/figure-markdown_github/fig4a-1.png index 30ba3b2..d11e8eb 100644 Binary files a/README_files/figure-markdown_github/fig4a-1.png and b/README_files/figure-markdown_github/fig4a-1.png differ diff --git a/README_files/figure-markdown_github/no_fct-1.png b/README_files/figure-markdown_github/no_fct-1.png new file mode 100644 index 0000000..07dcc84 Binary files /dev/null and b/README_files/figure-markdown_github/no_fct-1.png differ diff --git a/README_files/figure-markdown_github/ww2-1.png b/README_files/figure-markdown_github/ww2-1.png index 8339002..063a9ca 100644 Binary files a/README_files/figure-markdown_github/ww2-1.png and b/README_files/figure-markdown_github/ww2-1.png differ diff --git a/cran-comments.md b/cran-comments.md index 2d5701f..c8e7381 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -1,12 +1,11 @@ ## Why? -* New functionality (isotype picotgram glphys) -* No longer drops factor levels (bugfix) +* Latest revs to ggplot2 broke functionality +* Depends on ggplot2 >= 2.0.0 now ## Test environments -* local OS X install, R 3.3.1 & R-devel -* ubuntu 12.04 (on travis-ci) +* local OS X install, R 3.3.2 & R-devel +* ubuntu 12.04 (on travis-ci), R-devel, R-release, R-oldrel * win-builder (devel and release) ## R CMD check results * glyphs, isotype & pictograms are properly spelled -* moving personal e-mail address \ No newline at end of file diff --git a/man/iron.Rd b/man/iron.Rd index 91e1662..68feee1 100644 --- a/man/iron.Rd +++ b/man/iron.Rd @@ -19,7 +19,7 @@ parts <- c(80, 30, 20, 10) w1 <- waffle(parts, rows=8) w2 <- waffle(parts, rows=8) w3 <- waffle(parts, rows=8) -chart <- iron(w1, w2, w3) # print chart +## iron(w1, w2, w3) } diff --git a/man/waffle.Rd b/man/waffle.Rd index 800cbda..46598c6 100644 --- a/man/waffle.Rd +++ b/man/waffle.Rd @@ -4,15 +4,17 @@ \alias{waffle} \title{Make waffle (square pie) charts} \usage{ -waffle(parts, rows = 10, xlab = NULL, title = NULL, colors = NA, - size = 2, flip = FALSE, reverse = FALSE, equal = TRUE, pad = 0, - use_glyph = FALSE, glyph_size = 12, legend_pos = "right") +waffle(parts, rows = 10, keep = TRUE, xlab = NULL, title = NULL, + colors = NA, size = 2, flip = FALSE, reverse = FALSE, equal = TRUE, + pad = 0, use_glyph = FALSE, glyph_size = 12, legend_pos = "right") } \arguments{ \item{parts}{named vector of values to use for the chart} \item{rows}{number of rows of blocks} +\item{keep}{keep factor levels (i.e. for consistent legends across waffle plots)} + \item{xlab}{text for below the chart. Highly suggested this be used to give the "1 sq == xyz" relationship if it's not obvious}