plotly / plotly/plotly.R

Some heatmap labels not visible when other layers added (e.g. with `add_trace`)

未关闭
#2,069 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

主要语言
R
星标
2.7k
派生
641
PR 合并指标
30 天内没有已合并 PR

描述

Hi, thanks a lot for making such a great package :)!

I have the issue with labels. One can create a heatmap in plotly and see the labels (ht object). But once the new layer is added (e.g. with add_trace) the labels from the previous layer are not visible (ht_a1 object). Disabling labels from the second layer does not help (ht_a2 and ht_a3).

https://user-images.githubusercontent.com/41166437/140326488-f539949b-5baf-4e32-ad17-d3eb574cccf7.mp4

Both potential workaround are suboptimal (ht_a4 and ht_a5).

Thanks in advance for you help!

df <-
  data.frame(x = rep(1:10, 10),
             y = rep(1:10, each = 10),
             z = sample(1:100))
ht <-
  plotly::plot_ly(
    type = "heatmap",
    x = df$x,
    y = df$y,
    z = df$z
  )

# two layers: heatmap and single line
# some cells with heatmap labels (e.g. [2, 1], [1, 2], some with line labels (e.g. [1,1], [2,2]))
ldf <- data.frame(x = 1:8, y = c(1:5, 4:2))
ht_a1 <-
  plotly::add_paths(ht,
                    x = ldf$x,
                    y = ldf$y,
                    inherit = FALSE)

### disabling labels for single line does not enable labels for heatmap in related cells
ht_a2 <-
  plotly::add_paths(
    ht,
    x = ldf$x,
    y = ldf$y,
    inherit = FALSE,
    hoverinfo = "skip"
  )

ht_a3 <-
  plotly::add_paths(
    ht,
    x = ldf$x,
    y = ldf$y,
    inherit = FALSE,
    hoverinfo = "none"
  )
plotly::layout(ht_a3, hovermode="x")

## workaround #1 (restore labels from `heatmap` on the `line` layer)
ldf$z_idx <- ldf$x + 10 * (ldf$y - 1)
ldf$z <- df$z[ldf$z_idx]
ldf$label <- sprintf("x:%s\ny:%s\nz:%s", ldf$x, ldf$y, ldf$z)
ht_a4 <-
  plotly::add_paths(
    ht,
    x = ldf$x,
    y = ldf$y,
    inherit = FALSE,
    text = ldf$label,
    hoverinfo = "text"
  )

## workaround #2 (use with hovermode == "x")
# results in undesired behaviour (additional labels appearing)
ht_a5 <-
  plotly::add_paths(
    ht,
    x = ldf$x,
    y = ldf$y,
    inherit = FALSE,
    hoverinfo = "skip"
  ) %>% plotly::layout(hovermode = "x")


贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先运行提供的 R 复现,并在 add_paths 之后将单独的热图与 ht_a1、ht_a2 和 ht_a3 进行比较。跟踪添加另一层时热图标签和 hoverinfo 的行为;当原始热图标签无需任何一种 workaround 仍保持可见时,即表示完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
r
领域
data-visualization
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。