-
-
Notifications
You must be signed in to change notification settings - Fork 94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rcdimple
versions
#1
Comments
Was literally JUST thinking about tweeting about this Kent! |
Here is a crude function. library(waffle)
library(pipeR)
library(rcdimple)
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"
, height = height, width = width
) %>>%
xAxis( type = "addCategoryAxis", title = "" ) %>>%
yAxis( type = "addCategoryAxis", title = "" ) %>>%
default_colors( unique( dat$fill ) ) %>>%
set_bounds( x = "5%", y = "10%", width = "65%", height = "70%") %>>%
add_legend( x = "85%", y = "20%", width = "10%", height = "60%" ) %>>%
add_title(wf$labels$title)
) %>>%
tack( options = list(tasks = list(
htmlwidgets::JS(
'function(){
this.widgetDimple[0].axes.forEach(function(ax){
ax.shapes.remove()
})
}'
)
)))
} |
actually thinking a little more about this prob better to just do this and return a raw dimple. Then the user can adjust as they would like. 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()
})
}'
)
)))
} Some things a user might want to do %>>% tack( options = list(barGap = 0.5) ) # barGap 0 is prob most likely
%>>% set_bounds( x = "5%", y = "10%", width = "65%", height = "70%")
%>>% add_legend( x = "85%", y = "20%", width = "10%", height = "60%" ) |
Then for a both static and interactive, could do this. library(htmltools)
savings <- c('Mortgage ($84,911)'=84911, 'Auto and Tuition loans ($14,414)'=14414, 'Home equity loans ($10,062)'=10062, 'Credit Cards ($8,565)'=8565)
waffle(
savings/392, rows=7, size=0.5
, colors=c("#c7d4b6", "#a3aabd", "#a0d0de", "#97b5cf"), title = "Waffle Chart Awesomeness"
) %>>%
(
tagList(
HTML(base64::img( shiny::plotPNG(
function(){print(.)}
,height = 200, width = 800
)))
,as_rcdimple( ., height = 200, width = 800) %>>%
tack( options = list(barGap = 0) ) %>>%
add_legend( x = "85%", y = "20%", width = "10%", height = "60%" ) %>>%
set_bounds( x = "5%", y = "10%", width = "65%", height = "70%")
)
) %>>% html_print |
#added #ty |
Ok cool. I'll do a pull to make a little more robust and also might remove the pipe bit so that another dependency is not introduced. |
Love it, and coincides nicely with
rcdimple
, so I'll combine the two. The last example gets very close to a complete replication. Could easily make a function to make it one-liner.The text was updated successfully, but these errors were encountered: