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

Aperta
#2,502 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
r

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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
Lingua principale
R
Stelle
2.7k
Fork
641
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di plotly/plotly.R

Tutte le issue di plotly/plotly.R

Issue simili

Altre issue su R

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.