Some heatmap labels not visible when other layers added (e.g. with `add_trace`)
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- R
- Sterne
- 2.7k
- Forks
- 641
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
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).
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")
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne damit, die bereitgestellte R-Reproduktion auszuführen, und vergleiche nur die Heatmap mit ht_a1, ht_a2 und ht_a3 nach add_paths. Verfolge, wie sich die Beschriftungen der Heatmap und hoverinfo verhalten, wenn eine weitere Ebene hinzugefügt wird; fertig ist es, wenn die ursprünglichen Heatmap-Beschriftungen sichtbar bleiben, ohne einen der beiden Workarounds zu erfordern.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- r
- Bereich
- data-visualization
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100