Skip to content

dir = "v" also needs to swap nrow and ncol #1279

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
hadley opened this issue Aug 20, 2015 · 4 comments
Closed

dir = "v" also needs to swap nrow and ncol #1279

hadley opened this issue Aug 20, 2015 · 4 comments
Milestone

Comments

@hadley
Copy link
Member

hadley commented Aug 20, 2015

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 = 3)
base + facet_wrap(~class, nrow = 3, dir = "v")
@hadley hadley modified the milestone: v1.1.0 Oct 13, 2015
@hadley hadley closed this as completed in bbc1b5a Oct 14, 2015
@chrismerkord
Copy link

There's a bug here that is not apparent unless you use an nrow other than what it defaults to when NULL. For example, try:

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

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)

@chrismerkord
Copy link

I wasn't as specific about the diagnosis of the bug as I could have been. When you run:

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.

@hadley
Copy link
Member Author

hadley commented Nov 25, 2015

Can you please file a new bug?

@chrismerkord
Copy link

I filed a new bug: #1417

@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
None yet
Projects
None yet
Development

No branches or pull requests

2 participants