Skip to content

Fix the axes layout for facet grid/wrap. #619

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from

Conversation

alyst
Copy link
Contributor

@alyst alyst commented Jun 3, 2016

The PR fixes the labels of axes/anchors if the corresponding indices are >= 10 (otherwise the data/gridlines in some panels are missing).

For a test one can try

p <- ggplot( data.frame(x = rnorm(1000), y = rnorm(1000),
                   a = sample(1:20, 1000, replace=TRUE) ) ) +
  geom_point(aes(x=x, y=y)) + facet_wrap(~ a, scales = "free_x" )
ggplotly(p)

The PR fixes the behaviour for scales="free" and scales="free_x" case. For scales="free_y" case it fixes the missing panels, but the X axes at the bottom are still missing.

@alyst
Copy link
Contributor Author

alyst commented Jun 6, 2016

Also fixed the placement of X axes when then last row is not complete, the axes is attached to the lowest subplot in the column, not the last row of the whole plot. Otherwise plotly.js draws fake empty subplot to attach the axis to.

@cpsievert
Copy link
Collaborator

Thanks @alyst. I'm closing this, but you're contributions are much appreciated, and have been quite useful for identifying issues. Some of these ideas have been incorporated into #654.

@cpsievert cpsievert closed this Jul 25, 2016
@alyst
Copy link
Contributor Author

alyst commented Jul 27, 2016

@cpsievert i've looked at the code of your PR but have no time to test it. I think there could still be issues with axes anchoring if you have e.g xaxis21. Your code would transform it to xaxis2. Also i haven't understood whether you have a fix for axes anchoring if the last row is incomplete.

@alyst
Copy link
Contributor Author

alyst commented Mar 20, 2019

The issue with >10 indices of axes is fixed, but the issue with X axis placement on the incomplete last row is still in the plotly's master.

ggplotly handles the last row differently from ggplot2: ggplot() attaches the X axis to the last plot in the column, whereas ggplotly(ggplot()) always puts it to the last row, even when there are no plots at that position. IMHO the ggplot2 behaviour is better -- there are no "floating" axes, the axes are always attached to the plots.

I've rebased this PR to the master to fix the issue (it's on the same branch, but since the PR is closed the recent version is not shown). Could you please reopen the PR?

There's one testcase affected by the fix: "facet_wrap-free_y-2" (it also demonstrates the difference between ggplot and current ggplotly behaviours). I guess I also need to fix the reference .png, but I'm not sure how to properly do it.

@cpsievert
Copy link
Collaborator

Hi @alyst, for some reason I can't reopen...would you mind starting a new PR?

Also, thanks for the recent burst in PRs!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants