I would like to highlight points in an R plot_ly scatter based on whether the key column matches one of the elements of a query column of the data-point hovered-over by the user. I know you can set up non-reciprocal, hierarchical highlighting between points by populating the key field with lists: points will be highlighted if the elements in their key field form a subset of the elements of the selected point's key field. But I would like to highlight in a more flexible way.
This is a modified example from the r plotly page (down the bottom) using list-columns as keys:
d <- tibble::tibble(
x = 1:4,
y = 1:4,
key = list('A','B','C','D'),
query = list(c('A','C'), 'B',c('A','D'), c('A','B','D'))
)
highlight_key(d, ~ query) %>%
plot_ly(x = ~x, y = ~y, hoverinfo = "key") %>%
highlight("plotly_selected", color = "red") %>%
highlight(on = "plotly_hover", color = "red", selectize = F, opacityDim = 0.8)
'query' is a column of lists. I'd like points to be highlighted if their 'key' value is a subset of the elements in the list in the 'query' field of the point being hovered over. However right now they are only highlighted if their 'query' list is a subset of 'query' list of the selected point. e.g. I want hovering over point D to highlight points A, B and D, from searching the 'key' column with the elements of the 'query' column. But right now it doesn't highlight A because the query value for A {'A','C'} is not a subset of the query list for D {'A','B','D'}.