Last active
February 29, 2016 15:03
-
-
Save timelyportfolio/91e0b8c2b8cd4202baa2 to your computer and use it in GitHub Desktop.
waffle as_rcdimple separate so can source
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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