r - aggregating functions in ggvis add_tooltip -


i trying add frequency of each bar tooltip , having issues. attempted use group_by unsuccessfully. tooltip returns 4 each tooltip each bar.

mtcars %>%   ggvis(x = ~cyl) %>%   layer_histograms(fill="sky blue"                    , fillopacity:=.7                    , fillopacity.hover:=.9) %>%   group_by(cyl) %>%   add_tooltip(function(x) length(x)) 

this method has same issue. returns 4 each bar...

freq <- function(x) {   paste0("frequency: ", length(x)) }  mtcars %>%   ggvis(x = ~cyl) %>%   layer_histograms(fill="sky blue"                    , fillopacity:=.7                    , fillopacity.hover:=.9) %>%   group_by(cyl) %>%   add_tooltip(freq) 

to enable tool-tips values can create function all_values , add those.

all_values <- function(x) {   if(is.null(x)) return(null)   paste0(names(x), ": ", format(x), collapse = "<br />") } mtcars %>% group_by(cyl) %>%   ggvis(x = ~cyl) %>%   layer_histograms(fill="sky blue"                    , fillopacity:=.7                    , fillopacity.hover:=.9) %>%   add_tooltip(all_values, "hover") 

you can use information piece function want show. in case, upper value of piece of stacked bar chart.

mtcars %>% group_by(cyl) %>%   ggvis(x = ~cyl) %>%   layer_histograms(fill="sky blue"                    , fillopacity:=.7                    , fillopacity.hover:=.9) %>%   add_tooltip(function(df) (df$stack_upr_),"hover") 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -