I have a small issue about GGVIS in R studio.
I want to plot something and have more information on each point when I move my cursor on it. Thus, I am using GGVIS package and the add_tooltip() function to do it.
However when I run the code below, I obtain the plot but not the additional info when I move my cursor on the points.
Furthermore, I want to use the separate function (tooltip_test) because my real code is a bit more complex and the function would help me a lot.
library(ggvis)
test <- data.frame(ID=1:10, TIME=1:10, COUNTS=rep(1:2,5), EXTRA=c("A", "B", "C", "D", "E", "F", "G", "H", "I", "J"))
tooltip_test <- function(x) {
if (is.null(x)) return(NULL)
if(is.null(x$ID)) return(NULL)
sub_test = test[test$ID == x$ID, ]
paste0("Category: ", sub_test$EXTRA)
}
test %>%
ggvis(x= ~TIME, y= ~COUNTS) %>%
layer_points() %>%
add_tooltip(tooltip_test, "hover")