Browse Source

added as_rcdimple thanks to Kent Russell

pull/3/head
Bob Rudis 9 years ago
parent
commit
a0db7fc33a
  1. 23
      DESCRIPTION
  2. 10
      NAMESPACE
  3. 7
      R/waffle-package.R
  4. 42
      R/waffle.R
  5. 6
      README.Rmd
  6. 20
      man/as_rcdimple.Rd
  7. 2
      man/waffle.Rd

23
DESCRIPTION

@ -1,18 +1,35 @@
Package: waffle
Type: Package
Title: Create waffle charts (square pie charts)
Version: 0.1
Version: 0.2
Date: 2015-03-18
Author: Bob Rudis (@hrbrmstr)
Authors@R: c(
person("John", "Kiernander", role = c("aut", "cph"), comment = "dimple.js
library in htmlwidgets/lib, https://github.com/PMSI-AlignAlytics/dimple"),
person("Mike", "Bostock", role = c("aut", "cph"), comment = "d3.js
library in htmlwidgets/lib, http://d3js.org"),
person("Jeremy", "Stucki", role = c("aut", "cph"), comment = "d3-grid
library in htmlwidgets/lib, http://github.com/cpettitt/dagre-d3"),
person("Bob", "Rudis", role = c("aut", "cre"), comment = "R
interface", email = "bob@rudis.net"),
person("Kenton", "Russell", role = c("aut", "cre"), comment = "rcdimple",
email = "kent.russell@timelyportfolio.com"),
person("Ramnath", "Vaidyanathan", role = c("aut","ctb"), comment = "rCharts
common interace functions", email = "ramnath.vaidya@gmail.com")
)
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
License: MIT + file LICENSE
Imports:
RColorBrewer
RColorBrewer,
pipeR,
htmlwidgets,
rcdimple

10
NAMESPACE

@ -1,5 +1,13 @@
# Generated by roxygen2 (4.1.0.9000): do not edit by hand
# Generated by roxygen2 (4.1.0): do not edit by hand
export(as_rcdimple)
export(waffle)
import(RColorBrewer)
import(ggplot2)
importFrom(pipeR,"%>>%")
importFrom(rcdimple,add_title)
importFrom(rcdimple,default_colors)
importFrom(rcdimple,dimple)
importFrom(rcdimple,tack)
importFrom(rcdimple,xAxis)
importFrom(rcdimple,yAxis)

7
R/waffle-package.R

@ -3,4 +3,11 @@
#' @docType package
#' @author Bob Rudis (@@hrbrmstr)
#' @import ggplot2 RColorBrewer
#' @importFrom rcdimple dimple
#' @importFrom rcdimple xAxis
#' @importFrom rcdimple yAxis
#' @importFrom rcdimple default_colors
#' @importFrom rcdimple add_title
#' @importFrom rcdimple tack
#' @importFrom pipeR %>>%
NULL

42
R/waffle.R

@ -104,4 +104,44 @@ waffle <- function(parts, rows=10, xlab=NULL, title=NULL, colors=NA, size=2, fli
gg
}
}
#' Turn a ggplot waffle chart object into an htmlwidget
#'
#' Takes the output from \code{waffle} and turns it into an \code{rcdimple}
#' \code{htmlwidget}.
#'
#' @param wf waffle chart ggplot2 object
#' @param height height of the resultant \code{htmlwidget}
#' @param width width of the resultant \code{htmlwidget}
#' @export
as_rcdimple <- function( wf, height = NULL, width = NULL ){
ggplot_build(wf) %>>%
(.$data[[1]]) %>>%
( data.frame(
group = wf$scales$scales[[3]]$labels[
match(wf$data$value,unique(wf$data$value))
]
, .
, stringAsFactors = F
) ) %>>%
na.omit %>>%
(dat~
dimple( dat, y~x, type = "bar", groups = "group", width = width, height = height ) %>>%
xAxis( type = "addCategoryAxis", title = "" ) %>>%
yAxis( type = "addCategoryAxis", title = "" ) %>>%
default_colors( unique( dat$fill ) ) %>>%
add_title(wf$labels$title)
) %>>%
tack( options = list(tasks = list(
htmlwidgets::JS(
'function(){
this.widgetDimple[0].axes.forEach(function(ax){
ax.shapes.remove()
})
}'
)
)))
}

6
README.Rmd

@ -13,11 +13,13 @@ It uses ggplot2 and returns a ggplot2 object.
The following functions are implemented:
- `waffle`
- `waffle` : make a waffle chart ggplot2 object
- `as_rcdimple` : turn a waffle chart into a dimple.js htmlwidget
### News
- Version `0.1` released
- Version `0.2` released - added `as_rcdimple` thx to Kent Russell
### Installation
@ -52,7 +54,7 @@ waffle(parts, rows=8, size=1, colors=c("#969696", "#1879bf", "#009bda"),
waffle(parts/10, rows=3, colors=c("#969696", "#1879bf", "#009bda"),
title="Health records breaches as fraction of US Population",
xlab="One square == 10m ppl")
xlab="One square == 10m ppl")
# replicating an old favourite

20
man/as_rcdimple.Rd

@ -0,0 +1,20 @@
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/waffle.R
\name{as_rcdimple}
\alias{as_rcdimple}
\title{Turn a ggplot waffle chart object into an htmlwidget}
\usage{
as_rcdimple(wf, height = NULL, width = NULL)
}
\arguments{
\item{wf}{waffle chart ggplot2 object}
\item{height}{height of the resultant \code{htmlwidget}}
\item{width}{width of the resultant \code{htmlwidget}}
}
\description{
Takes the output from \code{waffle} and turns it into an \code{rcdimple}
\code{htmlwidget}.
}

2
man/waffle.Rd

@ -1,4 +1,4 @@
% Generated by roxygen2 (4.1.0.9000): do not edit by hand
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/waffle-package.R, R/waffle.R
\docType{package}
\name{waffle}

Loading…
Cancel
Save