`facet_wrap()` with `scales = "free_x"` squishes middle facets
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 45/100
- Issue-Typ
- Bug
- Klarheit
- Größtenteils klar
- Aktivitätsstatus
- Ruhig
- Tech-Stack
- javascript, r
- Bereich
- data-visualization, frontend
Rechercherichtung
Beginne damit, das bereitgestellte R/Shiny-MWE mit ggplot2, plotly und facet_wrap(scales = "free_x") auszuführen, und reproduziere anschließend die Größenänderungssequenz außerhalb von Shiny. Untersuche das erzeugte Plot-Layout und das responsive Verhalten während der Größenänderung; abgeschlossen ist die Aufgabe, wenn die mittleren Facet-Zeilen ihre erwarteten Höhen beibehalten und nach der Größenänderung kein Leerraum erscheint.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Summary
When using facet_wrap() with scales = "free_x", the middle facets rows appear squished.
MWE
This bug is most apparent when working in Shiny contexts:
library(ggplot2)
library(shiny)
library(plotly)
ui <- fluidPage(
plotlyOutput("p", height = "800px")
)
server <- function(input, output, session) {
output$p <- renderPlotly({
plt <- palmerpenguins::penguins |>
ggplot(
aes(x = sex)
) +
geom_bar() +
facet_wrap(
ggplot2::vars(species, island, year),
ncol = 2,
axes = "all",
scales = "free_x" # or "free"
)
plotly::ggplotly(plt)
})
}
shinyApp(ui, server)
The result is an output where the first and last row of facets look correct, but all the middle facet rows are squished and there's a bunch of whitespace inbetween:
Interestingly, if you use scales = "free_y" or scales = "fixed", the bug is not triggered:
Potential Cause
I believe this is an issue with the responsivity / css of the resulting plot. You can get this to trigger outside of shiny, by doing the following:
- Size your plot output window to result in a squished output, and run the following:
plt <- palmerpenguins::penguins |>
ggplot(
aes(x = sex)
) +
geom_bar() +
facet_wrap(
ggplot2::vars(species, island, year),
ncol = 2,
axes = "all",
scales = "free_x"
)
plotly::ggplotly(plt)
Result:
- Resize the plot window by increasing the height, and you get the weird result:
- Key observation: if you now re-run the code from step 1, with the window height already tall, it renders correctly:
This is why I think there's responsivity / css thing going on here -- I imagine Shiny is rendering to a smaller height, then resizing to fill the space of the div. Responsivity is broken, triggering the weird result.
Thanks for looking in to this!
- Vorherrschende Sprache
- R
- Sterne
- 2.7k
- Forks
- 641
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beitragsleitfaden
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus plotly/plotly.R
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 62/100
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 35/100
-
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 68/100
-
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 72/100
-
save_image Error Offen
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 52/100
Alle Issues in plotly/plotly.R
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
r-lib/pkgdepends#485 · 3 Kommentare ·
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 92/100
-
beginners blocker
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
-
enviPathR OffenBuild Error Build OK Build Warning policies-accepted pre-review precheck-passed
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 84/100
Bioconductor/BiocContributions#207 · 6 Kommentare ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 74/100
datacarpentry/semester-biology#1255 ·