Skip to content

Panels are different sizes when converting ggplot plot with facets #1099

Open

Description

@natbprice

When converting a ggplot plot with facets to a plotly object the panels are different sizes. Margins are not subtracted from top and bottom rows so these panels end up being taller. This makes it hard to compare among panels. Margins for top and bottom of panels are equal so longer x-axis labels result in large margins on tops of panels with large spacing between panels and a low data-ink ratio.

library(dplyr)
library(ggplot2)
library(plotly)
library(reshape2)

p <- ggplot(data = tips,
            aes(x = sex, y = total_bill)) +
  geom_jitter(width = 0.1, height = 0) +
  facet_wrap(day ~ time, scales = "free_x", ncol = 2) +
  theme(axis.text.x = element_text(angle = 45),
        strip.text.x = element_text(size = 8, 
                                    margin = margin(t = 1, r = 0, b = 1, l = 0, unit = "pt")))

q <- ggplotly(p) %>% 
  plotly::layout(margin = list(l = 80, r = 0, t = 100, b = 100, pad = 0))

d <- rbind(q$x$layout$yaxis4$domain, q$x$layout$yaxis3$domain, q$x$layout$yaxis2$domain, q$x$layout$yaxis$domain)
df <- data_frame(lb = d[,1], ub = d[,2]) %>% 
  mutate(range = ub - lb,
         panelSpacing = lb - lag(ub))

Activity

  1. robsalasco commented on Feb 16, 2020

    @robsalasco

    hi! any news about this bug?

  2. Dennishi0925 commented on Aug 30, 2020

    @Dennishi0925

    Are there any solutions to the bug?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions