plotly / plotly/plotly.R

Panels are different sizes when converting ggplot plot with facets

Offen
#1,099 3 Kommentare 5 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


When converting a ggplot plot with facets to a plotly object the panels are different sizes. Margins are not subtracted from top and bottom rows so these panels end up being taller. This makes it hard to compare among panels. Margins for top and bottom of panels are equal so longer x-axis labels result in large margins on tops of panels with large spacing between panels and a low data-ink ratio.

library(dplyr)
library(ggplot2)
library(plotly)
library(reshape2)

p <- ggplot(data = tips,
            aes(x = sex, y = total_bill)) +
  geom_jitter(width = 0.1, height = 0) +
  facet_wrap(day ~ time, scales = "free_x", ncol = 2) +
  theme(axis.text.x = element_text(angle = 45),
        strip.text.x = element_text(size = 8, 
                                    margin = margin(t = 1, r = 0, b = 1, l = 0, unit = "pt")))

q <- ggplotly(p) %>% 
  plotly::layout(margin = list(l = 80, r = 0, t = 100, b = 100, pad = 0))

d <- rbind(q$x$layout$yaxis4$domain, q$x$layout$yaxis3$domain, q$x$layout$yaxis2$domain, q$x$layout$yaxis$domain)
df <- data_frame(lb = d[,1], ub = d[,2]) %>% 
  mutate(range = ub - lb,
         panelSpacing = lb - lag(ub))

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

Reproduziere das Problem mit dem bereitgestellten ggplotly()-Beispiel und untersuche die in d gesammelten Werte des y-Achsenbereichs. Beginne damit nachzuverfolgen, wie Facet-Panels und Layout-Ränder konvertiert werden, und überprüfe anschließend, dass das obere und untere Panel gleich groß sind und dass der Abstand die konfigurierten Ränder widerspiegelt.

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

Neue Issues direkt in Ihr Postfach

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