悬停信息显示在绘图直方图 R 中的条形上方

发布于 2025-01-19 03:22:23 字数 311 浏览 5 评论 0原文

我正在尝试使用Plotly创建直方图,但是当我定义“ Hoverinfo”信息时,它会在栏上显示信息,而不是“内部”。 “在此处输入图像说明”

diamonds %>% plot_ly(x = ~cut, color = ~clarity, hoverinfo = 'text', text = ~carat)

我尝试使用add_histogram(),但似乎没有任何作用。我应该怎么办?

I'm trying to create an histogram with plotly, but when I define the 'hoverinfo' information, it displays the information over the bars and not 'inside'.
enter image description here

diamonds %>% plot_ly(x = ~cut, color = ~clarity, hoverinfo = 'text', text = ~carat)

I tried to use add_histogram() as well, but nothing seems to work. What should I do?

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

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

发布评论

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

评论(1

彻夜缠绵 2025-01-26 03:22:23

我对您的评论很感兴趣,因为您拥有最新的 plotly 版本,因此我下载了它并且可以复制您的问题。看来在 plotly.js 中处理默认 text 参数的方式发生了变化,请参阅 此处

条形迹线的文本位置现在默认为自动,因此如果您想使用文本而不显示在图形上,则需要显式设置 textposition="none"

不幸的是,当 type="histogram" 时,没有 textposition 参数。在您的情况下解决此问题的方法是将 text 参数替换为 hovertext

library(plotly)
diamonds %>% 
    plot_ly(
        x = ~cut, 
        color = ~clarity,
        type = "histogram",
        hoverinfo = "text", 
        hovertext = ~carat
    )

这应该可以解决问题。

I was intrigued by your comment that you had the most recent plotly version, so I downloaded it and I could replicate your issue. It looks like there has been a change in the way the default text argument is treated in plotly.js, see here:

textposition for bar traces now defaults to auto so if you want to use text without it appearing on the figure, you’ll need to explicitly set textposition="none"

Unfortunately, when type="histogram", there is no textposition argument. The way to fix this in your case is to replace the text argument with hovertext:

library(plotly)
diamonds %>% 
    plot_ly(
        x = ~cut, 
        color = ~clarity,
        type = "histogram",
        hoverinfo = "text", 
        hovertext = ~carat
    )

This should resolve the issue.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文