plotly / plotly/plotly.R

Bug report – colour-mapped markers on a date x-axis reset axis to 1970

Offen
#2,446 2 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

Hi

thank you for the great work on plotly for R. While building a simple time-series chart I noticed that mapping a numeric column to color inside a marker trace shifts the x-axis limits to the Unix epoch (1970-01-01). The same variable works fine when mapped to size. The reproducible examples below illustrate the behaviour. Any guidance or fix would be highly appreciated.

Reprex
library(plotly)
library(data.table)

# dummy data -------------------------------------------------------------
set.seed(1)
dt <- data.table(
  y            = cumsum(rnorm(200)),
  rank         = sample(1:100, 200, TRUE),
  size_metric  = rpois(200, 10),
  datetime     = seq(as.Date("2022-01-01"), by = "day", length.out = 200)
)

# -------- WORKS (no colour mapping) -------------------------------------
plot_ly(dt, type = "scatter", mode = "markers") |>
  add_trace(x = ~datetime, y = ~y,
            name = "points", size = ~size_metric) |>
  add_trace(x = ~datetime, y = ~y,
            name = "line", mode = "lines",
            line = list(color = "black"))
# x-axis shows correct 2022-20xx window

# -------- WORKS (size mapped to same field) -----------------------------
plot_ly(dt, type = "scatter", mode = "markers") |>
  add_trace(x = ~datetime, y = ~y,
            name = "points", size = ~rank) |>
  add_trace(x = ~datetime, y = ~y,
            name = "line", mode = "lines",
            line = list(color = "black"))
# ✓ still correct axis

# -------- FAILS (colour mapping) ----------------------------------------
plot_ly(dt, type = "scatter", mode = "markers") |>
  add_trace(x = ~datetime, y = ~y,
            name = "points", colour = ~rank) |>
  add_trace(x = ~datetime, y = ~y,
            name = "line", mode = "lines",
            line = list(color = "black"))
# ✗ x-axis resets to 1970-01-01
Expected

Axis limits stay within the data’s date range (2022-01-01 … 2022-07-20).

Actual

When colour = ~rank is used, the x-axis jumps to epoch 1970-01-01.

Tested with

packageVersion("plotly")  # 4.10.4
R.version.string          # R 4.3.2 (MacOS Darwing)

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

Beginne damit, das bereitgestellte R reprex mit plotly 4.10.4 auszuführen, und vergleiche die funktionierende Größenabbildung mit der fehlschlagenden colour-Abbildung. Verfolge, wie colour-zugeordnete Marker und Date-x-Werte vorbereitet werden; als erledigt gilt die Aufgabe, wenn die x-Achse bei der Verwendung von colour = ~rank innerhalb von 2022-01-01 bis 2022-07-20 bleibt.

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
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
45/100

Neue Issues direkt in Ihr Postfach

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