plotly / plotly/plotly.R

ggplotly() unable to fit 4 plots in 3 columns using a "ggplot() + facet_wrap()" object

Offen
#1,939 0 Kommentare 0 Reaktionen 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

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:
newplot (6)
newplot (7)
newplot (8)
newplot (9)

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

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 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

Neue Issues direkt in Ihr Postfach

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