ggplotly() unable to fit 4 plots in 3 columns using a "ggplot() + facet_wrap()" object
Nobody has claimed this yet.
- Dominant language
- R
- Stars
- 2.7k
- Forks
- 641
- PR merge metrics
- No merged PRs in 30d
Description
Hi,
It turns out that ggplotly() is unable to fit 4 plots in 3columns when the ggplot object to be converted was designed using this structure ggplot(df, aes(x,y) + facet_wrap(~ var, ncol = 3). It does not matter which example you use.
Let's use this example from the plotly community website, see section "labels":
https://plotly.com/ggplot2/facet_wrap/#labels
df <- diamonds[sample(1:nrow(diamonds), size = 1000), ]
# Create labels
labs <- c("Best","Second best","Third best","Average", "Average","Third Worst","Second Worst","Worst")
levels(df$clarity) <- rev(labs)
# filter variable "clarity" to get 4 plots in the facet
df <- df %>%
filter(clarity %in% c("Worst", "Average", "Third best", "Best"))
p <- ggplot(df, aes(carat, price)) +
geom_point() +
facet_wrap(~ clarity, ncol = 3) # make clear that 3 columns are needed
fig <- ggplotly(p)
fig
I will attach the outputs so you can see the bug:




It is easy tu bypass this issue, just changing the number of columns. Nevertheless, it would be great if this didn't happen.
Kind regards,
Sergi
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 diamonds example from the Plotly facet_wrap labels page, using ggplot() with facet_wrap(~ clarity, ncol = 3) and converting it with ggplotly(). Inspect the facet_wrap conversion and compare the rendered result with the original ggplot. Done means four plots fit correctly in three columns in the converted figure.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- r
- Domain
- data-visualization
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100