plotly / plotly/plotly.R

Unequal facet heights

Aperta
#2,100 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Lingua principale
R
Stelle
2.7k
Fork
641
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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)

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia eseguendo il reprex R fornito con ggplotly(), quindi confronta l’output di facet_grid() e facet_wrap() con il risultato ggplot dimensionato correttamente. Segui la conversione del layout delle facet di ggplotly e individua il punto in cui le altezze dei pannelli o la spaziatura diventano disuguali. Il lavoro è completo quando entrambi gli esempi producono pannelli di altezza uguale senza sovrapposizioni tra le tacche dell’asse y.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
plotly, r
Ambito
data-visualization
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.