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

Đang mở
#2,502 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
r
Lĩnh vực
data-visualization

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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
Ngôn ngữ chính
R
Star
2.7k
Fork
641
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của plotly/plotly.R

Tất cả issue của plotly/plotly.R

Issue tương tự

Thêm issue về R

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.