plotly / plotly/plotly.R

layout breaks with facet_wrap when employing scales=free

Open
#1,301 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

ggplotly
Dominant language
R
Stars
2.7k
Forks
641
PR merge metrics
No merged PRs in 30d

Description

I have a problem combining plotly::ggplotly (v4.7.1) with facet_wrap (v3.0.0) that I can't seem to generalise but is reproducible with a particular dataset (summary metrics for a set of tweets):

require(tidyverse)
require(plotly)
d = read_csv('https://gist.githubusercontent.com/geotheory/21c4eacbf38ed397f7cf984f8d92e931/raw/9148df79326f53a66a8cc363241a440752487357/data.csv')
d = d %>% mutate(key = fct_reorder(key, n)) # order the bars
p = ggplot(d, aes(key, n)) + geom_bar(stat='identity') + 
  facet_wrap(~ set, scales='free', nrow=1) +
  labs(x=NULL, y=NULL) + coord_flip()
print(p)

enter image description here

Enter ggplotly:

print(ggplotly(p))

enter image description here

This seems to relate to the combination of nrow=1 and scales='free' arguments. Any ideas about the cause?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the supplied R example with the linked dataset and the reported ggplot2 and plotly versions, comparing the ggplot and ggplotly renders. Trace how ggplotly handles facet_wrap with scales='free', coord_flip(), and nrow=1. Done means the converted plot preserves the expected facet layout without breaking the free scales.

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
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.