Subplot panel height not consistent

Offen
#2,144 4 Kommentare 1 Reaktion 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Anfängerfreundlichkeit
35/100
Issue-Typ
Bug
Klarheit
Größtenteils klar
Aktivitätsstatus
Veraltet
Tech-Stack
r

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.

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)
Vorherrschende Sprache
R
Sterne
2.7k
Forks
641
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus plotly/plotly.R

Alle Issues in plotly/plotly.R

Ähnliche Issues

Weitere Issues zu R

Neue Issues direkt in Ihr Postfach

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