问题
When using highcharter
for interactive plots, how can I specify that datapoints in a group must highlight together?
library(highcharter)
library(dplyr)
library(tidyr)
dfr <- data.frame(sample=c("A","B","C","D"),part=c(2,3,4,6),cat=c(5,7,3,3))
dfr1 <- dfr %>% tidyr::gather(key=metric,value=value,-sample)
dfr1
sample metric value
1 A part 2
2 B part 3
3 C part 4
4 D part 6
5 A cat 5
6 B cat 7
7 C cat 3
8 D cat 3
dfr1 %>%
hchart(.,"scatter",hcaes(x=metric,y=value,group=factor(sample))) %>%
hc_xAxis(type="category",title=list(text="Metrics"),crosshair=TRUE) %>%
hc_yAxis(type="linear",title=list(text="Counts"),crosshair=TRUE) %>%
hc_chart(zoomType="xy",inverted=T) %>%
hc_tooltip(useHTML=TRUE,formatter = JS("function(){
return('<b>Sample: </b>'+this.point.sample+'</br>')}"))
In this example, when I hover over the blue point (Sample A), I would like all other blue points (Sample A's) to be highlighted as well.
来源:https://stackoverflow.com/questions/48263285/highcharter-highlight-points-in-a-group