Skip to content

Instantly share code, notes, and snippets.

@timelyportfolio
Last active February 29, 2016 15:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timelyportfolio/91e0b8c2b8cd4202baa2 to your computer and use it in GitHub Desktop.
Save timelyportfolio/91e0b8c2b8cd4202baa2 to your computer and use it in GitHub Desktop.
waffle as_rcdimple separate so can source
as_rcdimple <- function( wf, height = NULL, width = NULL ) {
# not import since optional dependency
# check here to see if rcdimple is available
if(!requireNamespace("rcdimple", quietly=TRUE)) stop("please devtools::install_github('timelyportfolio/rcdimple')", call. = FALSE)
# let ggplot2 do the work and build the chart
# let ggplot2 do the work and build the chart
gb <- ggplot_build(wf)
dimp <- rcdimple::dimple(
data.frame(
group = wf$scales$scales[[1]]$labels[
match(wf$data$value,unique(wf$data$value))
]
,gb$data[[1]]
,stringsAsFactors = F
)
, y~x
, type = "bar"
, groups = "group"
, width = width
, height = height
, xAxis = list( type = "addCategoryAxis", title = "" )
, yAxis = list( type = "addCategoryAxis", title = "" )
, defaultColors = unique( na.omit(gb$data[[1]])$fill )
, title = list( text = wf$labels$title )
, tasks = list(
JS(
'function(){
this.widgetDimple[0].axes.forEach(function(ax){
ax.shapes.remove()
})
}'
)
)
)
return(dimp)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment