2016-07-18 38 views
0

我想設置標籤,只有光標指向的值纔會顯示。相反,當前代碼顯示任何x值的所有y值。如何以陰謀顯示只有懸停的標籤?

library(plotly) 
data_frame(noiseLevel=sort(rep(seq(10,50,10),5)), 
      temperature=rep(seq(50,90,10),5), 
      testScore=c(30,75,20,50,70, 
         40,60,45,20,50, 
         30,20,30,40,30, 
         60,30,60,20,50, 
         30,50,20,40,60)) -> dt 

plot_ly(data=dt, 
     x = noiseLevel,   
     y = testScore, 
     color=factor(temperature), 
     name = "linear", line = list(shape = "linear")) 

回答

0

正如rld01提到的,這可以在工具欄上改變,但你也可以更改默認通過R.下面是代碼。

library(plotly) 
data.frame(noiseLevel=sort(rep(seq(10,50,10),5)), 
      temperature=rep(seq(50,90,10),5), 
      testScore=c(30,75,20,50,70, 
         40,60,45,20,50, 
         30,20,30,40,30, 
         60,30,60,20,50, 
         30,50,20,40,60)) -> dt 

plot_ly(data=dt, 
     x = noiseLevel,   
     y = testScore, 
     color=factor(temperature), 
     name = "linear", line = list(shape = "linear")) %>% 
    layout(hovermode="closest") 

# with upcoming plotly 
# devtools::install_github("ropensci/plotly") 
plot_ly(data=dt, 
     x = ~noiseLevel,   
     y = ~testScore, 
     color=~factor(temperature), 
     name = "linear", line = list(shape = "linear")) %>% 
    layout(hovermode="closest")