pdil / usmap

🗺 Create US maps including Alaska and Hawaii in R
https://usmap.dev/
GNU General Public License v3.0
74 stars 16 forks source link

`usmap::plot_usmap` - getting an error message about ggplot element hierarchy #109

Closed cmansoo closed 6 months ago

cmansoo commented 6 months ago

Hello, I recently ran into this error running the plot_usmap function. The function does not seem to be working with any data and I'm not quite sure what the issue is. Below is an example

library(usmap)
plot_usmap(data=statepop, values="pop_2022")

<error/rlang_error>
Error in `mapply()`:
! The `legend.justification.inside` theme element is
  not defined in the element hierarchy.
---
Backtrace:
    ▆
 1. ├─base (local) `<fn>`(x)
 2. └─ggplot2:::print.ggplot(x)
 3.   ├─ggplot2::ggplot_gtable(data)
 4.   └─ggplot2:::ggplot_gtable.ggplot_built(data)
 5.     └─ggplot2:::plot_theme(plot)
 6.       └─base::mapply(validate_element, theme, names(theme), MoreArgs = list(element_tree = get_element_tree()))
 7.         └─ggplot2 (local) `<fn>`(dots[[1L]][[98L]], dots[[2L]][[98L]], element_tree = `<named list>`)
 8.           └─cli::cli_abort(...)
 9.             └─rlang::abort(...)

Including my sessionInfo

> sessionInfo()
R version 4.3.2 (2023-10-31 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 11 x64 (build 22631)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.utf8 
[2] LC_CTYPE=English_United States.utf8   
[3] LC_MONETARY=English_United States.utf8
[4] LC_NUMERIC=C                          
[5] LC_TIME=English_United States.utf8    

time zone: America/New_York
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets 
[6] methods   base     

other attached packages:
[1] usmap_0.7.1

loaded via a namespace (and not attached):
 [1] utf8_1.2.4         generics_0.1.3    
 [3] class_7.3-22       KernSmooth_2.23-22
 [5] digest_0.6.33      magrittr_2.0.3    
 [7] evaluate_0.23      grid_4.3.2        
 [9] pkgload_1.3.3      fastmap_1.1.1     
[11] processx_3.8.2     e1071_1.7-14      
[13] DBI_1.1.3          ps_1.7.5          
[15] fansi_1.0.5        scales_1.2.1      
[17] cli_3.6.1          crayon_1.5.2      
[19] rlang_1.1.2        units_0.8-5       
[21] munsell_0.5.0      reprex_2.0.2      
[23] withr_2.5.2        yaml_2.3.7        
[25] tools_4.3.2        usmapdata_0.2.2   
[27] dplyr_1.1.3        colorspace_2.1-0  
[29] ggplot2_3.4.4      vctrs_0.6.4       
[31] R6_2.5.1           proxy_0.4-27      
[33] lifecycle_1.0.4    classInt_0.4-10   
[35] fs_1.6.3           pkgconfig_2.0.3   
[37] callr_3.7.3        clipr_0.8.0       
[39] pillar_1.9.0       gtable_0.3.4      
[41] glue_1.6.2         Rcpp_1.0.11       
[43] sf_1.0-15          xfun_0.41         
[45] tibble_3.2.1       tidyselect_1.2.0  
[47] rstudioapi_0.15.0  knitr_1.45        
[49] farver_2.1.1       htmltools_0.5.7   
[51] rmarkdown_2.25     compiler_4.3.2  

Thank you

pdil commented 6 months ago

@cmansoo, try updating ggplot2 to version 3.5.0 or higher

cmansoo commented 6 months ago

Thank you! It solved the problem. One quick suggestion maybe - when importing the package (library(usmap)) it would be nice if it would display a message like "the package requires ggplot2 3.5.0 or higher"

pdil commented 6 months ago

Thank you! It solved the problem. One quick suggestion maybe - when importing the package (library(usmap)) it would be nice if it would display a message like "the package requires ggplot2 3.5.0 or higher"

Yeah I have received a lot of reports with the same problem, so I will be sure to do that next time 😓. Glad it solved your issue!