plotly / plotly/plotly.R

ggplotly doesn't display geom_rect with ymin = -Inf and ymax = Inf

Offen
#1,559 6 Kommentare 17 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

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

Beschreibung

In ggplot::geom_rect(), one can specify the aesthetics ymin = -Inf and ymax = Inf, which will draw the rectangles to the limit of the plotting area. Apparently, ggplotly does not support this behaviour, and will fail to display the rectangles when a ggplot object with such a geom_rect is passed.

Motivation This behaviour of geom_rect is especially useful for indicating time periods of interest when plotting time series. Workarounds such as manually specifying the ymin and ymax limits to mimic the behaviour are much less effective: it can be difficult to know in advance what those limits should be, and they are affected by expand settings in the scale specification.

# Plot definition
example_plot = economics %>%
  ggplot() +
  geom_line(aes(x = date, y = psavert)) +
  geom_rect(data = data.frame(xmin = seq(as.Date('1970-01-01'),
                                         as.Date('2010-01-01'),
                                         '10 years'),
                              xmax = seq(as.Date('1975-01-01'),
                                         as.Date('2015-01-01'),
                                         '10 years'),
                              ymin = -Inf, ymax = Inf),
            aes(xmin = xmin, xmax = xmax, ymin = ymin, ymax = ymax))
# Base ggplot object
example_plot

image

# Calling ggplotly
example_plot %>% ggplotly()

image

Note ggplotly image above captured using 'export' function on Viewer pane in RStudio.

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 economics- und geom_rect-Beispiel durch ggplotly() laufen zu lassen, und verfolge dann den Einstiegspunkt der ggplotly-Konvertierung für geom_rect. Vergleiche den Basis-ggplot und die gerenderte Ausgabe; fertig ist es, wenn Rechtecke mit ymin = -Inf und ymax = Inf bis zu den Grenzen des Plotbereichs angezeigt werden.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
plotly, 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

Neue Issues direkt in Ihr Postfach

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