情节:R显示Ymin和Ymax的HoverText

发布于 2025-01-24 16:00:45 字数 658 浏览 3 评论 0原文

在使用绘制功能区图的“悬停数据”函数时,仅显示Ymax值。

样品tibble如下

tib <- tibble(year = 1:4, min = rnorm(4), max = 15+rnorm(4))  

plot_ly(tib, x= ~year) %>% 
add_ribbons(ymin = ~ min, ymax = ~ max, line = list(color = "lightgrey"),
              markers = list(color = "lightgrey"),
              fillcolor = "rgba(7, 164, 181, 0.2)", name = "95% region", 
              hovertemplate = paste( "Rate: %{y:.1f}<br>year: %{x} </br>"))

所示

我还如何显示Ymin Hovertext?

When using the function "Compare data on hover" for a plotly ribbon plot, only the ymax value is displayed.

A sample tibble is as follows

tib <- tibble(year = 1:4, min = rnorm(4), max = 15+rnorm(4))  

plot_ly(tib, x= ~year) %>% 
add_ribbons(ymin = ~ min, ymax = ~ max, line = list(color = "lightgrey"),
              markers = list(color = "lightgrey"),
              fillcolor = "rgba(7, 164, 181, 0.2)", name = "95% region", 
              hovertemplate = paste( "Rate: %{y:.1f}<br>year: %{x} </br>"))

The output is
enter image description here

How do I display the ymin hovertext as well?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

绮烟 2025-01-31 16:00:46

一种可能性是禁用此工具提示并添加两行:

plot_ly(tib, x= ~year) %>% 
  add_ribbons(ymin = ~ min, ymax = ~ max, line = list(color = "lightgrey"),
              fillcolor = "rgba(7, 164, 181, 0.2)", name = "95% region",
              hoverinfo = "none") %>%
  add_lines(y = ~ min,
            hovertemplate = "Rate: %{y:.1f}<br>year: %{x} </br>") %>%
  add_lines(y = ~ max,
            hovertemplate = "Rate: %{y:.1f}<br>year: %{x} </br>")

A possibility is to disable this tooltip and add two lines:

plot_ly(tib, x= ~year) %>% 
  add_ribbons(ymin = ~ min, ymax = ~ max, line = list(color = "lightgrey"),
              fillcolor = "rgba(7, 164, 181, 0.2)", name = "95% region",
              hoverinfo = "none") %>%
  add_lines(y = ~ min,
            hovertemplate = "Rate: %{y:.1f}<br>year: %{x} </br>") %>%
  add_lines(y = ~ max,
            hovertemplate = "Rate: %{y:.1f}<br>year: %{x} </br>")
偏爱自由 2025-01-31 16:00:46

大型聚会迟到了,但是由于我遇到了同样的问题,所以我通过在丝带中添加文本并将Hoverinfo设置为文本:

library(plotly)
library(tibble)

tib <- tibble(year = 1:4, min = rnorm(4), max = 15 + rnorm(4))  

plot_ly(tib, x = ~year) %>% 
  add_ribbons(ymin = ~ min, ymax = ~ max, line = list(color = "lightgrey"),
              text = ~ paste0("[", round(min, 1L), ",", round(max, 1L), "]"),
              markers = list(color = "lightgrey"),
              fillcolor = "rgba(7, 164, 181, 0.2)", name = "95% region", 
              hovertemplate = "Rate: %{text}<br>year: %{x} </br>")

Mega late to the party, but because I had the same problem, I solved it by adding a text to the ribbons and set the hoverinfo to text:

library(plotly)
library(tibble)

tib <- tibble(year = 1:4, min = rnorm(4), max = 15 + rnorm(4))  

plot_ly(tib, x = ~year) %>% 
  add_ribbons(ymin = ~ min, ymax = ~ max, line = list(color = "lightgrey"),
              text = ~ paste0("[", round(min, 1L), ",", round(max, 1L), "]"),
              markers = list(color = "lightgrey"),
              fillcolor = "rgba(7, 164, 181, 0.2)", name = "95% region", 
              hovertemplate = "Rate: %{text}<br>year: %{x} </br>")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文