ggplotly() unable to fit 4 plots in 3 columns using a "ggplot() + facet_wrap()" object
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- R
- Sterne
- 2.7k
- Forks
- 641
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
Hi,
It turns out that ggplotly() is unable to fit 4 plots in 3columns when the ggplot object to be converted was designed using this structure ggplot(df, aes(x,y) + facet_wrap(~ var, ncol = 3). It does not matter which example you use.
Let's use this example from the plotly community website, see section "labels":
https://plotly.com/ggplot2/facet_wrap/#labels
df <- diamonds[sample(1:nrow(diamonds), size = 1000), ]
# Create labels
labs <- c("Best","Second best","Third best","Average", "Average","Third Worst","Second Worst","Worst")
levels(df$clarity) <- rev(labs)
# filter variable "clarity" to get 4 plots in the facet
df <- df %>%
filter(clarity %in% c("Worst", "Average", "Third best", "Best"))
p <- ggplot(df, aes(carat, price)) +
geom_point() +
facet_wrap(~ clarity, ncol = 3) # make clear that 3 columns are needed
fig <- ggplotly(p)
fig
I will attach the outputs so you can see the bug:




It is easy tu bypass this issue, just changing the number of columns. Nevertheless, it would be great if this didn't happen.
Kind regards,
Sergi
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Reproduziere das Problem mit dem diamonds-Beispiel von der Plotly-Seite „facet_wrap labels“, indem du ggplot() mit facet_wrap(~ clarity, ncol = 3) verwendest und es mit ggplotly() konvertierst. Untersuche die facet_wrap-Konvertierung und vergleiche das gerenderte Ergebnis mit dem ursprünglichen ggplot. Erledigt ist die Aufgabe, wenn vier Plots in der konvertierten Abbildung korrekt in drei Spalten passen.
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
- 45/100