`facet_wrap()` with `scales = "free_x"` squishes middle facets
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 4/5
- Tempo estimado
- 3-5 dias
- Facilidade para iniciantes
- 45/100
- Tipo de issue
- Bug
- Clareza
- Razoavelmente clara
- Status de atividade
- Pouca atividade
- Stack de tecnologia
- javascript, r
- Domínio
- data-visualization, frontend
Direção de pesquisa
Comece executando o MWE de R/Shiny fornecido com ggplot2, plotly e facet_wrap(scales = "free_x"), e depois reproduza a sequência de redimensionamento fora do Shiny. Inspecione o layout do gráfico gerado e o comportamento responsivo durante o redimensionamento; considera-se concluído quando as linhas de facets do meio mantêm suas alturas esperadas e nenhum espaço em branco aparece após o redimensionamento.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
Summary
When using facet_wrap() with scales = "free_x", the middle facets rows appear squished.
MWE
This bug is most apparent when working in Shiny contexts:
library(ggplot2)
library(shiny)
library(plotly)
ui <- fluidPage(
plotlyOutput("p", height = "800px")
)
server <- function(input, output, session) {
output$p <- renderPlotly({
plt <- palmerpenguins::penguins |>
ggplot(
aes(x = sex)
) +
geom_bar() +
facet_wrap(
ggplot2::vars(species, island, year),
ncol = 2,
axes = "all",
scales = "free_x" # or "free"
)
plotly::ggplotly(plt)
})
}
shinyApp(ui, server)
The result is an output where the first and last row of facets look correct, but all the middle facet rows are squished and there's a bunch of whitespace inbetween:
Interestingly, if you use scales = "free_y" or scales = "fixed", the bug is not triggered:
Potential Cause
I believe this is an issue with the responsivity / css of the resulting plot. You can get this to trigger outside of shiny, by doing the following:
- Size your plot output window to result in a squished output, and run the following:
plt <- palmerpenguins::penguins |>
ggplot(
aes(x = sex)
) +
geom_bar() +
facet_wrap(
ggplot2::vars(species, island, year),
ncol = 2,
axes = "all",
scales = "free_x"
)
plotly::ggplotly(plt)
Result:
- Resize the plot window by increasing the height, and you get the weird result:
- Key observation: if you now re-run the code from step 1, with the window height already tall, it renders correctly:
This is why I think there's responsivity / css thing going on here -- I imagine Shiny is rendering to a smaller height, then resizing to fill the space of the div. Responsivity is broken, triggering the weird result.
Thanks for looking in to this!
- Linguagem predominante
- R
- Estrelas
- 2.7k
- Forks
- 641
- Métricas de merge de PRs
- Nenhum PR com merge em 30d
Preparar o ambiente
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de plotly/plotly.R
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 62/100
-
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 35/100
-
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 68/100
-
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 72/100
-
save_image ErrorAberta
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 52/100
Todas as issues de plotly/plotly.R
Issues semelhantes
-
Dificuldade 2/5 Meio dia Facilidade para iniciantes 78/100
ThinkR-open/datadiff#59 ·
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 82/100
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 82/100
duckdb/duckdb-r#2773 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
tidymodels/parsnip#1444 ·
Mantenedores costumam responder em até 4 dias
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100