hafen / geofacet

R package for geographical faceting with ggplot2
https://hafen.github.io/geofacet/
Other
336 stars 43 forks source link

Error: The given dimensions cannot hold all panels. Please increase `ncol` or `nrow` #306

Closed adamsoliman closed 3 years ago

adamsoliman commented 3 years ago

Hello!

I get "Error: The given dimensions cannot hold all panels. Please increase ncol or nrow" when I run this code:

ggplot(presecription_dataUS, aes(year, DOSAGE_UNIT)) + geom_line() + facet_geo(~ BUYER_STATE, grid = "us_state_grid2", label = "code") + scale_x_continuous(labels = function(x) paste0("'", substr(x, 3, 4))) + labs(title = "Opiate Prescriptions from Retail and Chain Pharmacies between 2006-2014", x = "Year", y = "Monthly Opiate Prescriptions")

I see if you get this error with facet_wrap(), you would just add ncol = some# (or nrow = some#), but it doesn't seem to work here, as I keep increasing ncol incrementally until 10 million but I get the same error. Note that I have 8 years of monthly data for many units, where the y variable has a range from 0 to 3 million and a mean of 14000; there are about 7 million observations.

rlang::last_error() gives Backtrace:

  1. (function (x, ...) ...
  2. geofacet:::print.facet_geo(x)
  3. geofacet::get_geofacet_grob(x)
  4. ggplot2::ggplotGrob(x)
  5. ggplot2:::ggplot_build.ggplot(x)
  6. layout$setup(data, plot$data, plot$plot_env)
  7. ggplot2:::f(..., self = self)
    1. self$facet$compute_layout(data, self$facet_params)
    2. ggplot2:::f(...)
    3. ggplot2::wrap_dims(n, params$nrow, params$ncol)

sessionInfo() gives R version 4.0.3 (2020-10-10) Platform: x86_64-apple-darwin17.0 (64-bit) Running under: macOS Mojave 10.14.6

Am I missing something, or is there something else I can try?

adamsoliman commented 3 years ago

Below is a light version of the primary dataset I was using in the code above (~5000 observations, same issue though). Its zipped so that I could attach it but its only 18kb.

lightversion.RData.zip

adamsoliman commented 3 years ago

@hafen if there is anything else I can provide, please let me know, and thanks for such a great package!