gpt4 book ai didi

r - Plotly:如何删除工具提示中的置信区间值(从误差条中)?

转载 作者:行者123 更新时间:2023-12-04 10:57:15 25 4
gpt4 key购买 nike

我正在尝试删除 R Plotly 图中工具提示中的误差条值。

我试过玩弄 hovertext来自这里的参数:https://plot.ly/r/hover-text-and-formatting/但无法让它工作。

我在一个有时会出现误差条的函数中使用这些,但大多数时候没有(因为我没有数据)所以不需要工具提示中的额外细节(因为它只显示 +0/-0 )。

在下面的例子中,我希望它只显示 2010, 5没有置信区间。

enter image description here

有任何想法吗?

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()得到这个:

剧情:

enter image description here

完整代码:
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"))

关于r - Plotly:如何删除工具提示中的置信区间值(从误差条中)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59098612/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com