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

problem in get_domains(nPanels, nRows, margins) in ggplotly.R #1628

Closed
hjia222 opened this issue Sep 26, 2019 · 1 comment · Fixed by #1974
Closed

problem in get_domains(nPanels, nRows, margins) in ggplotly.R #1628

hjia222 opened this issue Sep 26, 2019 · 1 comment · Fixed by #1974

Comments

@hjia222
Copy link

hjia222 commented Sep 26, 2019

I encountered a strange error recently:

plot2 <- plot + facet_wrap( ~ group, ncol=2)
p <- ggplotly(plot2,tooltip = c("x","y","label"))
Error in get_domains(nPanels, nRows, margins) :  The sum of the widths and heights arguments must be less than 1

My ncol = 2 in a facet wrap ggplot, and ncol = 11.

get_domains <- function(nplots = nPanels, nrows = nRows, margins = margins, 
                          widths = NULL, heights = NULL) {
    if (length(margins) == 1) margins <- rep(margins, 4)
    if (length(margins) != 4) stop("margins must be length 1 or 4", call. = FALSE)
    ncols <- ceiling(nplots / nrows)
    widths <- widths %||% rep(1 / ncols, ncols)
    heights <- heights %||% rep(1 / nrows, nrows)
    if (length(widths) != ncols) {
      stop("The length of the widths argument must be equal ",
           "to the number of columns", call. = FALSE)
    }
    if (length(heights) != nrows) {
      stop("The length of the heights argument is ", length(heights),
           ", but the number of rows is ", nrows, call. = FALSE)
    }
    if (any(widths < 0) | any(heights < 0)) {
      stop("The widths and heights arguments must contain positive values")
    }
    if (sum(widths) > 1 | sum(heights) > 1) {
      stop("The sum of the widths and heights arguments must be less than 1")
    }
  ...
  }

The auto-sizing calculated height as in the get_domains function, but there is some issue with sum(heights) for certain numbers:

> heights <- heights %||% rep(1 / nrows, nrows)

> heights
 [1] 0.09090909 0.09090909 0.09090909 0.09090909 0.09090909 0.09090909 0.09090909 0.09090909 0.09090909 0.09090909 0.09090909

> sum(heights) > 1
[1] TRUE
> sum(heights)
[1] 1
@hjia222
Copy link
Author

hjia222 commented Sep 26, 2019

It could be just a simple issue of divid and sum function conflict.

> sum(rep(1/11,11))
[1] 1
> sum(rep(1/11,11)) > 1
[1] TRUE

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 a pull request may close this issue.

1 participant