usmap icon indicating copy to clipboard operation
usmap copied to clipboard

theme element missing to plot

Open HBasiuk opened this issue 1 year ago • 1 comments

When trying to plot the map data a theme element is missing in the element hierarchy.

To Reproduce Steps to reproduce the behavior: Running states <- plot_usmap("states")

counties <- plot_usmap("counties") cowplot::plot_grid(states, counties, nrow = 1) Provides this error. Error in mapply(): ! The legend.justification.inside theme element is not defined in the element hierarchy. Run rlang::last_trace() to see where the error occurred.

  1. └─cowplot::plot_grid(states, counties, nrow = 1)
  2. └─cowplot::align_plots(...)
  3. └─base::lapply(...)
    
  4.   └─cowplot (local) FUN(X[[i]], ...)
    
  5.     ├─cowplot::as_gtable(x)
    
  6.     └─cowplot:::as_gtable.default(x)
    
  7.       ├─cowplot::as_grob(plot)
    
  8.       └─cowplot:::as_grob.ggplot(plot)
    
  9.         └─ggplot2::ggplotGrob(plot)
    
  10.           ├─ggplot2::ggplot_gtable(ggplot_build(x))
    
  11.           └─ggplot2:::ggplot_gtable.ggplot_built(ggplot_build(x))
    
  12.             └─ggplot2:::plot_theme(plot)
    
  13.               └─base::mapply(validate_element, theme, names(theme), MoreArgs = list(element_tree = get_element_tree()))
    

Expected behavior A clear and concise description of what you expected to happen.

Environment (please complete the following information):

  • Platform: [e.g. macOS, Windows, Linux]
  • version output:

  • sessionInfo() output:
<body>
<!--StartFragment-->
R version 4.2.1 (2022-06-23 ucrt) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10 x64 (build 19045)  Matrix products: default  locale: [1] LC_COLLATE=English_Canada.utf8  LC_CTYPE=English_Canada.utf8    [3] LC_MONETARY=English_Canada.utf8 LC_NUMERIC=C                    [5] LC_TIME=English_Canada.utf8      attached base packages: [1] stats     graphics  grDevices utils     datasets  methods   base       other attached packages:  [1] usmap_0.7.0.9000 zoo_1.8-12       ggpubr_0.6.0     spData_2.2.2      [5] gganimate_1.0.8  ggthemes_4.2.4   dplyr_1.1.1      lubridate_1.9.2   [9] raster_3.6-20    sp_1.6-0         ggplot2_3.4.2    ncdf4_1.21       [13] terra_1.7-23     sf_1.0-12        tidyr_1.3.0       loaded via a namespace (and not attached):  [1] pkgload_1.3.2      carData_3.0-5      shiny_1.7.4        remotes_2.4.2       [5] progress_1.2.2     sessioninfo_1.2.2  backports_1.4.1    pillar_1.9.0        [9] lattice_0.20-45    glue_1.6.2         digest_0.6.33      ggsignif_0.6.4     [13] promises_1.2.0.1   colorspace_2.1-0   cowplot_1.1.1      htmltools_0.5.5    [17] httpuv_1.6.9       pkgconfig_2.0.3    devtools_2.4.5     broom_1.0.4        [21] gifski_1.6.6-1     purrr_1.0.1        xtable_1.8-4       scales_1.2.1       [25] processx_3.8.1     tweenr_2.0.2       later_1.3.0        timechange_0.2.0   [29] tibble_3.2.1       proxy_0.4-27       car_3.1-2          farver_2.1.1       [33] generics_0.1.3     usethis_2.1.6      ellipsis_0.3.2     cachem_1.0.8       [37] withr_2.5.0        cli_3.6.1          magrittr_2.0.3     crayon_1.5.2       [41] mime_0.12          memoise_2.0.1      ps_1.7.4           fs_1.6.1           [45] fansi_1.0.4        rstatix_0.7.2      class_7.3-20       pkgbuild_1.4.0     [49] profvis_0.3.7      tools_4.2.1        prettyunits_1.1.1  hms_1.1.3          [53] lifecycle_1.0.3    stringr_1.5.0      munsell_0.5.0      callr_3.7.3        [57] compiler_4.2.1     e1071_1.7-13       rlang_1.1.0        classInt_0.4-9     [61] units_0.8-2        grid_4.2.1         rstudioapi_0.14    htmlwidgets_1.6.2  [65] miniUI_0.1.1.1     gtable_0.3.3       codetools_0.2-18   abind_1.4-5        [69] DBI_1.2.2          curl_5.0.0         R6_2.5.1           knitr_1.42         [73] fastmap_1.1.1      utf8_1.2.3         KernSmooth_2.23-20 stringi_1.7.12     [77] Rcpp_1.0.11        vctrs_0.6.1        usmapdata_0.2.2    tidyselect_1.2.0   [81] xfun_0.38          urlchecker_1.0.1
--
 
> | >
>

<!--EndFragment-->
</body>
</html>

Additional context Add any other context about the problem here.

HBasiuk avatar Mar 15 '24 19:03 HBasiuk

I noticed you're using ggplot2_3.4.2, can you try updating to version 3.5.0+ of ggplot2 and see if that resolves the issue?

pdil avatar Mar 16 '24 03:03 pdil