I'm trying to add a tooltip to my ggvis plot. I basically want to add the density number when I hover the mouse over the density plot. This is what I have right now:
mtcars %>% ggvis(~wt, fill := "red") %>%
layer_densities() %>%
add_axis("x", title = "Weight") %>%
scale_numeric("x", domain = c(0, 5), nice = FALSE, clamp = TRUE) %>%
add_tooltip(function(df){density(df$wt)})
But when I hover, I get this error:
Error in density.default(df$wt) : argument 'x' must be numeric
Thanks!