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

ggarrange fails if eiter ncol = 1 or nrow = 1 #144

Closed
GegznaV opened this issue Dec 18, 2018 · 4 comments
Closed

ggarrange fails if eiter ncol = 1 or nrow = 1 #144

GegznaV opened this issue Dec 18, 2018 · 4 comments

Comments

@GegznaV
Copy link

GegznaV commented Dec 18, 2018

In the example below ggarrange fails to create a single plot if eiter ncol = 1 or nrow = 1:

library(ggplot2)

fig_1 <- 
  ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width)) +
  geom_line()

ggpubr::ggarrange(fig_1, fig_1, ncol = 1)
ggpubr::ggarrange(fig_1, fig_1, nrow = 1)

I by specifying ncol = 1 I expected all plots on one page arranged in one column. But the result is two separate plots and the output in the console:

$`1`

$`2`

attr(,"class")
[1] "list"      "ggarrange"

This should either be fixed (preferred), or a meaningful warning message should appear with explanations what happened, or, if the behavior I described is expected, more information should be included in the documentation.

In the situation:

ggpubr::ggarrange(fig_1, fig_1, nrow = 0)

A meaningful error message that nrow must be > 0 would also be preffered instead of Error in 1:(rows * cols) : NA/NaN argument.

@ashenkin
Copy link

+1, except that it's not just a matter of ncol/nrow = 1. This happens when only ncol or only nrow is specified. i.e.,
ggpubr::ggarrange(fig_1, fig_1, fig_1, ncol = 2)
fails as well.

@kassambara
Copy link
Owner

In the current version:

  • If you want to arrange 2 , 3, ..., or n plots by rows only, you need to specify nrow = n, where n is the number of plots
  • Similarly, if you want to arrange 2 , 3, ..., or n plots by columns only, you need to specify ncol = n

In your example, the following R code should work:

# Arrange two plots in two successive columns
ggpubr::ggarrange(fig_1, fig_1, ncol = 2)

# Arrange two plots in two successive rows
ggpubr::ggarrange(fig_1, fig_1, nrow = 2)

I will update ggarrange(), so that it can automatically guess the correct layout for the options ncol=1 and nrow=1

@kassambara
Copy link
Owner

fixed now thanks

@mielk132
Copy link

mielk132 commented Jul 27, 2022

I had the same error as GegznaV ( running ‘4.1.3’ in Rstudio), but it worked when I supplied 1.5. It would not show in Rstudio's viewing window when I set nrow =2 & ncol =1. It worked when printed to pdf.

ggarrange(p,p2, labels = c("A","B"),combine.legend = TRUE, legend = "right", ncol = 2, nrow= 1.5)

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

No branches or pull requests

4 participants