使用highcharter
进行交互式绘图时,如何指定组中的数据点必须一起突出显示?
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>')}"))
在这个例子中,当我将鼠标悬停在蓝点(样本A)上时,我希望所有其他蓝点(样本A)也被突出显示。