plotly / plotly/plotly.R

Unequal facet heights

Ouverte
#2,100 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Langage dominant
R
Étoiles
2.7k
Forks
641
Métriques de merge des PR
Aucune PR mergée en 30 j

Description

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)

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Commencez par exécuter le reprex R fourni avec ggplotly(), puis comparez les sorties de facet_grid() et facet_wrap() avec le résultat ggplot correctement dimensionné. Suivez la conversion de la disposition des facettes par ggplotly et identifiez à quel endroit les hauteurs des panneaux ou l’espacement deviennent inégaux. Le travail est considéré comme terminé lorsque les deux exemples génèrent des panneaux de hauteur égale sans chevauchement des graduations de l’axe y.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
plotly, r
Domaine
data-visualization
Type d'issue
Bug
Difficulté
3/5
Temps estimé
1-2 jours
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
45/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.