plotly / plotly/plotly.R

Subplot panel height not consistent

Offen
#2,144 4 Kommentare 1 Reaktion 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

There doesn't seem to be a way to set the total figure size for subplot().
Individual panel height can be specified in the call to plot_ly and (as i understand it) that height is scaled with the number of panels to become the total figure size.

I tried using this by passing to each subplot the individual plotheight multiplied with the number of subplots (nrows) so the total height of the total figure would be plotheight * nrows.
It turns out the heights aren't strictly adhered too.
Comparing the total height of the first two panels you can clearly see the x axes are at different heights:

subplot height mismatch

generate_subplot <- function(nrows, margin = NULL){

  if(is.null(margin)) margin = c(0,0,0,0)

  p <- plotly::plot_ly(mtcars, 
    x = ~cyl, y = ~mpg, 
    color = ~rownames(.data), 
    type = "bar",
    height = 150 * nrows
  ) %>% plotly::layout(
    showlegend = FALSE,
    shapes = list(
      list(
        type = 'rect',
        fillcolor = "gray", 
        line = list(color = "gray"), 
        opacity = 0.05,
        x0 = 0, x1 = 1,
        y0 = 0, y1 = 1,
        xref = 'paper',
        yref = 'paper'
      )
    )
  )
  
  plotly::subplot(
    rep_len(list(p), nrows),
    nrows = nrows,
    margin = margin
  )

}

generate_subplot(2)
generate_subplot(4)
generate_subplot(8)

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ühre zunächst das bereitgestellte generate_subplot-Beispiel für 2, 4 und 8 Zeilen aus und vergleiche die Panel- und x-Achsenhöhen in den gerenderten Abbildungen. Verfolge, wie subplot() die wiederholten plot_ly-Objekte und ihre Höhenwerte kombiniert; erledigt ist die Aufgabe, wenn jedes Panel die angeforderte einheitliche Höhe hat und die Gesamthöhe der Abbildung erwartungsgemäß skaliert.

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

Neue Issues direkt in Ihr Postfach

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