plotly / plotly/plotly.R

category axis and shapes not playing well when data representing numbers and xref = "x"

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

Providing a list of strings representing numbers for category axis converts them to number rather than keeping them as strings.
This for me results in the inability to use shapes to shade part of the graph.

Example of what is not working:

newplot (6)

library(plotly)

# Sample data
x <- c("1234", "2345", "3456", "4567")
y <- c(10, 15, 8, 12)

# Create a Plotly chart with a bar plot
fig <- plot_ly(x = ~x, y = ~y)

# Define a rectangle shape
shapes <- list(
  list(
    type = "rect",
    line = list(color = "red"),
    x0 = "1234", x1 = "2345",
    y0 = 0, y1 = 1,
    xref = "x",
    yref = "paper"
  )
)

# Add the rectangle shape to the layout
fig <- fig %>% layout(
  title = 'Highlighting with Lines', 
  xaxis = list(
    type = 'category',
    autotypenumbers = 'strict'
  ),
  shapes = shapes
)

# Display the chart
fig

Example of what is working:

newplot (7)

library(plotly)

# Sample data
x <- c("#1234", "#2345", "#3456", "#4567")
y <- c(10, 15, 8, 12)

# Create a Plotly chart with a bar plot
fig <- plot_ly(x = ~x, y = ~y)

# Define a rectangle shape
shapes <- list(
  list(
    type = "rect",
    line = list(color = "red"),
    x0 = "#1234", x1 = "#2345",
    y0 = 0, y1 = 1,
    xref = "x",
    yref = "paper"
  )
)

# Add the rectangle shape to the layout
fig <- fig %>% layout(
  title = 'Highlighting with Lines', 
  xaxis = list(
    type = 'category',
    autotypenumbers = 'strict'
  ),
  shapes = shapes
)

# Display the chart
fig

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, die mitgelieferte R-Reproduktion mit plot_ly() und layout() auszuführen, und vergleiche numerisch aussehende Kategorienbeschriftungen mit den funktionierenden Beschriftungen, denen '#' vorangestellt ist. Verfolge, wie xaxis type='category' und autotypenumbers='strict' sowohl für Balkendaten als auch für Shapes mit xref='x' behandelt werden; die Aufgabe ist erfüllt, wenn numerisch aussehende Zeichenfolgen kategorial bleiben und das Rechteck die vorgesehenen Kategorien umspannt.

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
45/100

Neue Issues direkt in Ihr Postfach

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