簡體   English   中英

Plotly:如何刪除工具提示中的置信區間值(從誤差條中)?

[英]Plotly: How to remove the confidence interval values (from the error bar) in the tooltip?

我正在嘗試刪除 R Plotly 圖中工具提示中的誤差條值。

我曾嘗試使用這里的hovertext參數: https : hovertext但無法讓它工作。

我在一個函數中有這些,有時會有誤差條,但大多數時候沒有(因為我沒有數據)所以不需要工具提示中的額外細節(因為它只顯示+0/-0 )。

在下面的示例中,我希望它只顯示2010, 5沒有置信區間。

在此處輸入圖片說明

有任何想法嗎?

library(tidyverse)
library(plotly)

data <- tibble(x = c(2010, 2011, 2012),
               y = c(5, 6, 7),
               err_high = c(1, 1, 1),
               err_low = c(0.9, 1, 1.1))

#plotly graph
plot_ly() %>%
  add_trace(data = data,  x = ~x, y = ~y,
            name = 'Actual', type = 'scatter', mode = 'lines+markers',
            line = list(shape = 'linear', width= 4, dash = 'solid'),
            error_y = list(type = "data", symmetric = FALSE, array = ~err_high, arrayminus = ~err_low)) %>%
  layout(xaxis = list(title = 'Year'),
         yaxis = list (title = 'Value', rangemode = "tozero"))

你可以包括

 text=paste(data$x, data$y, sep=', '),
 hoverinfo='text',

add_trace()中得到這個:

陰謀:

在此處輸入圖片說明

完整代碼:

library(tidyverse)
library(plotly)

data <- tibble(x = c(2010, 2011, 2012),
               y = c(5, 6, 7),
               err_high = c(1, 1, 1),
               err_low = c(0.9, 1, 1.1))

#plotly graph
plot_ly() %>%
  add_trace(data = data,  x = ~x, y = ~y,
            name = 'Actual', type = 'scatter', mode = 'lines+markers',
            line = list(shape = 'linear', width= 4, dash = 'solid'),
            text=paste(data$x, data$y, sep=', '),
            hoverinfo='text',
            error_y = list(type = "data", symmetric = FALSE, array = ~err_high, arrayminus = ~err_low)) %>%
  layout(xaxis = list(title = 'Year'),
         yaxis = list (title = 'Value', rangemode = "tozero"))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM