Search code examples
ggvis

add tooltip with count to layer_bars


Suppose I have the following graph

library(ggvis)
mtcars%>% ggvis(~factor(cyl)) %>% layer_bars()

How can I add a tooltip with the count variable?

Thanks


Solution

  • This does the trick:

    library(ggvis)
    mtcars  %>% ggvis(~factor(cyl)) %>% layer_bars() %>%
      add_tooltip(function(df) (df$stack_upr_ - df$stack_lwr_))