I'd like to customize the tooltip shown when a user hovers over a scatterplot point. To do this, I need to pull data out of the data object passed to format.contents. However, not all of the fields from my data.frame are getting into data. How can I add fields to data, or otherwise get the other columns from the data.frame into the right place?
Here is an example that should illustrate what I mean:
data.frame(
x = rnorm(200),
y = rnorm(200),
group = sample(letters[1:3], size=200, replace=T),
label = sample(letters[4:26], size=200, replace=T)
) %>%
billboarder(data=.) %>%
bb_aes(x = x, y = y, group=group, label=label) %>%
bb_scatterplot() %>%
bb_tooltip(grouped=FALSE,
contents = htmlwidgets::JS(
"function(data, titleFormat, valueFormat, color) {console.log(data);return `<table><tr><td>${data[0].label}</td></tr><tr><td>${data[0].x}</td></tr><tr><td>${data[0].value}</td></tr></table>`;}"
))
As of now, the labels are all undefined, because data has group for both the id and name fields.
I'd like to customize the tooltip shown when a user hovers over a scatterplot point. To do this, I need to pull data out of the
dataobject passed toformat.contents. However, not all of the fields from mydata.frameare getting intodata. How can I add fields todata, or otherwise get the other columns from thedata.frameinto the right place?Here is an example that should illustrate what I mean:
As of now, the labels are all
undefined, becausedatahasgroupfor both theidandnamefields.