Panels are different sizes when converting ggplot plot with facets
Nobody has claimed this yet.
- Dominant language
- R
- Stars
- 2.7k
- Forks
- 641
- PR merge metrics
- No merged PRs in 30d
Description
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))
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with the supplied ggplotly() example and inspect the y-axis domain values collected in d. Start by tracing how facet panels and layout margins are converted, then verify that the top and bottom panels have equal sizes and that spacing reflects the configured margins.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- r
- Domain
- data-visualization
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100