Skip to content
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

nrow and ncol are not swapped correctly for vertical facetting #1417

Closed
chrismerkord opened this issue Nov 25, 2015 · 0 comments
Closed

nrow and ncol are not swapped correctly for vertical facetting #1417

chrismerkord opened this issue Nov 25, 2015 · 0 comments
Labels
bug an unexpected problem or unintended behavior
Milestone

Comments

@chrismerkord
Copy link

There's a bug in facet-wrap.r on lines 89-90 that is not apparent unless you use an nrow other than what it defaults to when nrow is NULL. For example, try:

mpg2 <- subset(mpg, cyl != 5 & drv %in% c("4", "f") & class != "2seater")
base <- ggplot(mpg2, aes(displ, hwy)) + 
  geom_blank() + 
  xlab(NULL) + 
  ylab(NULL)
base + facet_wrap(~class, nrow = 2, dir = "v")

you should get a figure with 2 rows. Instead the figure has 3 rows. Inspecting the plot shows that nrow and ncol both have a value of NULL.

Likewise when you run

base + facet_wrap(~class, ncol = 2, dir = "v")

both nrow and ncol are 2 when it should be nrow == 2 and ncol == NULL.

The problem is that the swap code always results in nrow and ncol being equal or both being NULL, depending on which argument is defined:

# swap
nrow <- sanitise_dim(ncol)
ncol <- sanitise_dim(nrow)  # nrow here is not what you thought it was!

You'll have to create a dummy variable to swap them, e.g.:

# swap
nrow_swap <- ncol
ncol_swap <- nrow
nrow <- sanitise_dim(nrow_swap)
ncol <- sanitise_dim(ncol_swap)

I mentioned this in #1279 but I should have started a new issue instead.

@hadley hadley added this to the v2.1.0 milestone Jan 26, 2016
@hadley hadley added the bug an unexpected problem or unintended behavior label Jan 26, 2016
@hadley hadley closed this as completed in 8e93597 Feb 4, 2016
@lock lock bot locked as resolved and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

2 participants