Bug: ggplotly with geom_line and custom tooltip does not show lines when tooltip varies per data point

未關閉
#2,502 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

評估

難度
4/5
預估耗時
3-5 天
新手友好度
35/100
Issue 類型
缺陷
描述清晰度
基本清楚
活躍度
活躍
技術堆疊
r

研究方向

Start by running the three reproductions in the issue. Compare the trace that ggplotly() builds for geom_point against geom_line when the text aesthetic varies, for example by inspecting plotly_build() output. The fault is probably in how the line trace's hover text is converted, not in the plot itself. Done when a geom_line with a per-point tooltip renders its line and the tooltip still works.

由索引模型根據 Issue 內容生成。

描述

Hello,

I have stumbled across a very strange little bug, if I try to make a custom tooltip on a plot converted from ggplot2 with ggplotly, then it works fine with geom_point but breaks (nothing is plotted) with geom_line. But, only when the text of the tooltip varies with the data.

For example, here we have everything working as expected with geom_point:

library(plotly)
p <- mtcars |>
  mutate(
    text = paste0("test: ", row.names(mtcars))
  ) |>
  ggplot(aes(x = disp, y = mpg, text = text)) +
  geom_point()

ggplotly(p, tooltip = "text")
Image

However, if I now use geom_line instead, the data disappears even though it must be there as the tooltip works:

library(plotly)
p <- mtcars |>
  mutate(
    text = paste0("test: ", row.names(mtcars))
  ) |>
  ggplot(aes(x = disp, y = mpg, text = text)) +
  geom_line()

ggplotly(p, tooltip = "text")
Image

But, if I change the tooltip text back so that it's a constant string (i.e. doesn't change with the data) then everything plots fine, again.

library(plotly)
p <- mtcars |>
  mutate(
    text = paste0("test: ", "constant")
  ) |>
  ggplot(aes(x = disp, y = mpg, text = text)) +
  geom_line()

ggplotly(p, tooltip = "text")
Image

What's even weirder is that the plotting will work fine with a varying tooltip, but only when it's the default tooltip:

library(plotly)
p <- mtcars |>
  mutate(
    text = paste0("test: ", "constant")
  ) |>
  ggplot(aes(x = disp, y = mpg)) +
  geom_line()

ggplotly(p)
Image
主要語言
R
星號
2.7k
分支
641
PR 合併指標
30 天內沒有已合併 PR

環境準備

  • 沒有 Dockerfile 或 Docker Compose 檔案
  • 沒有 Pull Request 範本
  • 閱讀貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

plotly/plotly.R 的其他 Issue

查看 plotly/plotly.R 的全部 Issue

相似的 Issue

更多 R Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。