I've been playing around with the nice ggvis package. I'm doing a custom linear regression and wanted a tooltip to show info about each data point. However, when I add my regression line, the tooltip appears when I hover over the line, and shows then the info about the first datapoint (see screenshot). I provide this simple reproducible example:
library(ggvis)
mtc <- mtcars
lm=with(mtc,lm(mpg~wt))
mtc$fit=lm$coefficients[1]+mtcars$wt*lm$coefficients[2]
mtc$id <- 1:nrow(mtc) # Add an id column to use ask the key
all_values <- function(x) {
if(is.null(x)) return(NULL)
row <- mtc[mtc$id == x$id, ]
paste0(names(row), ": ", format(row), collapse = "
")
}
mtc %>% ggvis(x = ~wt, y = ~mpg, key := ~id) %>%
layer_points() %>%layer_lines(x= ~wt,y= ~fit)%>%
add_tooltip(all_values, "hover")
This produces this
I would like to exclude the regression line from the tooltip so it only shows info about the data points. Is there a way to achieve this? Thank you for your help!