Unequal facet heights
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- R
- Sterne
- 2.7k
- Forks
- 641
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
In the reprex below, the first and last panels are noticeably taller than the others (note the y axis ticks are overlapping for the remaining panels).
library(plotly)
#> Loading required package: ggplot2
#>
#> Attaching package: 'plotly'
#> The following object is masked from 'package:ggplot2':
#>
#> last_plot
#> The following object is masked from 'package:stats':
#>
#> filter
#> The following object is masked from 'package:graphics':
#>
#> layout
library(plyr)
#>
#> Attaching package: 'plyr'
#> The following objects are masked from 'package:plotly':
#>
#> arrange, mutate, rename, summarise
date <- rep(as.Date(1:365,origin='2011-1-1'),7)
location <- factor(rep(1:7,365))
product <- rep(letters[1:7], each=365)
value <- c(sample(1:10, size=365, replace=T),
sample(1:3, size=365, replace=T),
sample(10:100, size=365, replace=T),
sample(1:50, size=365, replace=T),
sample(1:20, size=365, replace=T),
sample(50:100, size=365, replace=T),
sample(1:100, size=365, replace=T))
dat<-data.frame(date,location,product,value)
p <- ggplot(dat, aes(x=date, y=value, color=location, group=location)) +
geom_line()+
theme(panel.spacing.y = ggplot2::unit(1, "lines")) +
facet_grid(product ~ ., scales = "fixed")
ggplotly(p)

(Also, the legend compresses the first few panels awkwardly, but that is a separate issue).
The problem also occurs with facet_wrap():
library(plotly)
#> Loading required package: ggplot2
#>
#> Attaching package: 'plotly'
#> The following object is masked from 'package:ggplot2':
#>
#> last_plot
#> The following object is masked from 'package:stats':
#>
#> filter
#> The following object is masked from 'package:graphics':
#>
#> layout
library(plyr)
#>
#> Attaching package: 'plyr'
#> The following objects are masked from 'package:plotly':
#>
#> arrange, mutate, rename, summarise
date <- rep(as.Date(1:365,origin='2011-1-1'),7)
location <- factor(rep(1:7,365))
product <- rep(letters[1:7], each=365)
value <- c(sample(1:10, size=365, replace=T),
sample(1:3, size=365, replace=T),
sample(10:100, size=365, replace=T),
sample(1:50, size=365, replace=T),
sample(1:20, size=365, replace=T),
sample(50:100, size=365, replace=T),
sample(1:100, size=365, replace=T))
dat<-data.frame(date,location,product,value)
p <- ggplot(dat, aes(x=date, y=value, color=location, group=location)) +
geom_line()+
theme(panel.spacing.y = ggplot2::unit(1, "lines")) +
facet_wrap(ncol = 1, vars(product), scales = "fixed")
ggplotly(p)

This issue doesn't appear to be coming from ggplot, but rather from ggplotly:
library(plotly)
#> Loading required package: ggplot2
#>
#> Attaching package: 'plotly'
#> The following object is masked from 'package:ggplot2':
#>
#> last_plot
#> The following object is masked from 'package:stats':
#>
#> filter
#> The following object is masked from 'package:graphics':
#>
#> layout
library(plyr)
#>
#> Attaching package: 'plyr'
#> The following objects are masked from 'package:plotly':
#>
#> arrange, mutate, rename, summarise
date <- rep(as.Date(1:365,origin='2011-1-1'),7)
location <- factor(rep(1:7,365))
product <- rep(letters[1:7], each=365)
value <- c(sample(1:10, size=365, replace=T),
sample(1:3, size=365, replace=T),
sample(10:100, size=365, replace=T),
sample(1:50, size=365, replace=T),
sample(1:20, size=365, replace=T),
sample(50:100, size=365, replace=T),
sample(1:100, size=365, replace=T))
dat<-data.frame(date,location,product,value)
p <- ggplot(dat, aes(x=date, y=value, color=location, group=location)) +
geom_line()+
theme(panel.spacing.y = ggplot2::unit(1, "lines")) +
facet_grid(product ~., scales = "fixed")
print(p)

Created on 2022-01-12 by the reprex package (v2.0.1)
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
Beginnen Sie damit, das bereitgestellte R-reprex mit ggplotly() auszuführen, und vergleichen Sie anschließend die Ausgaben von facet_grid() und facet_wrap() mit dem korrekt dimensionierten ggplot-Ergebnis. Verfolgen Sie die Umwandlung des Facet-Layouts durch ggplotly und ermitteln Sie, an welcher Stelle die Panelhöhen oder Abstände ungleich werden. Als abgeschlossen gilt die Aufgabe, wenn beide Beispiele Panels gleicher Höhe ohne überlappende y-Achsen-Ticks rendern.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- plotly, 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