[英]Is there a way to not display hover values for add_trace values in R plotly?
我想知道是否有辦法不在 plotly 圖 output 上顯示 add_trace 值? 下面的代碼生成一系列累積的年度折線圖。 插入了 add_trace 添加以在圖中添加一條垂直虛線。 但是,當我在圖形上顯示 hover 時,它顯示了垂直線的值 - 可以關閉它,但允許累積年度線的 hover 值嗎? 我希望通過調整下面的代碼來做到這一點。
謝謝。
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)
您應該可以在add_trace()
調用中使用hoverinfo='none'
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"
)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.