plotly / plotly/plotly.R

Data gets dropped in add_trace and consequently points have the wrong color if NA is present

Offen
#2,497 3 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Vorherrschende Sprache
R
Sterne
2.7k
Forks
641
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

Have a look at the following code:

library(plotly)
x = c(NA, 2, 3, 4, 5)
color = c(0, 0, 0.5, 1, 1)
# If you try to plot it this way, you get mismatched colors. The NA seems to have been silently dropped and then the wrong indices aligned. The colors of points 2 and 3 are now blue, of 4 is purple and of 5 is green.
plotly::plot_ly()|>
    plotly::add_trace(
      type = "scatter",
      mode = "markers",
      x = x,
      y = 0,
      marker = list(
        color = color,
        cmin = 0,
        cmax = 1,
        colorscale = list(list(0, "blue"), list(0.5, "purple"), list(1, "green"))
      )
    ) |>
    plotly::layout(
      showlegend = FALSE
    ) |>
    plotly::hide_colorbar() 

It produces a plot with wrong colors:

Image

I think this is unacceptable behavior, especially since this is not what happens if you do it in the what I consider the classical way:

data.frame(x=x, color=color) |> 
  plot_ly(x=~x, color=~color, y=0, colors = c("blue", "purple", "green")) |> 
  hide_colorbar()
Image

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Führen Sie das bereitgestellte R-Beispiel über plotly::add_trace aus und vergleichen Sie die Markerfarben mit dem data.frame-Beispiel. Verfolgen Sie, wie add_trace NA-Werte in x behandelt und den Markerfarbenvektor ausrichtet, und fügen Sie Regressionstests hinzu, die zeigen, dass Nicht-NA-Punkte ihre entsprechenden Farben behalten.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
r
Bereich
data-visualization
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Ruhig
Klarheit
Klar beschrieben
Anfängerfreundlichkeit
72/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.