Home > Enterprise >  Is there a way to not display hover values for add_trace values in R plotly?
Is there a way to not display hover values for add_trace values in R plotly?

Time:08-16

I was wanting to know if there is a way of not showing the add_trace values on the plotly graph output? The code below produces a series of cumulative annual line graphs. The add_trace addition was inserted to add a dashed vertical line to the graph. However, when I hover over the graphic it shows the values for the vertical line - can this be turned off, but allow hover values for the cumulative annual lines? I was hoping to do this with a tweak of the code below.

Thanks.

df %>% 
  filter(op_area_ocode == 'ALL') %>% mutate(Year = as.character(R.Year), DoY = as.Date(DoY.N, origin = "1972-01-01") - 1) %>% 
  plot_ly(., x = ~ DoY, y = ~cni, color = ~Year, colors = c("#D3D3D3","#D3D3D3","#D3D3D3","#D3D3D3","black","#E69F00","#56B4E9", "#009E73", "#AA4499"), type = 'scatter', mode = 'lines') %>%
  layout(title = paste("Reports"), xaxis = list(title = "", type = "date", tickformat = "%d %b"), yaxis = list (title = "Number of reports")) %>% 
  add_trace(x = as.Date("1972-08-15"),type = 'scatter', mode = 'lines', line = list(color = 'red', width=0.5, dash ="dot"),name = '', showlegend = FALSE) 

CodePudding user response:

You should be able to use hoverinfo='none' in your add_trace() call

df %>% 
  filter(op_area_ocode == 'ALL') %>% mutate(Year = as.character(R.Year), DoY = as.Date(DoY.N, origin = "1972-01-01") - 1) %>% 
  plot_ly(., x = ~ DoY, y = ~cni, color = ~Year, colors = c("#D3D3D3","#D3D3D3","#D3D3D3","#D3D3D3","black","#E69F00","#56B4E9", "#009E73", "#AA4499"), type = 'scatter', mode = 'lines') %>%
  layout(title = paste("Reports"), xaxis = list(title = "", type = "date", tickformat = "%d %b"), yaxis = list (title = "Number of reports")) %>% 
  add_trace(x = as.Date("1972-08-15"),
            type = 'scatter',
            mode = 'lines',
            line = list(color = 'red', width=0.5, dash ="dot"),
            name = '',
            showlegend = FALSE,
            hoverinfo="none"
  )
  • Related