Skip to content

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

Closed
@hjia222

Description

@hjia222

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions