ropensci / NLMR

📦 R package to simulate neutral landscape models 🏔
https://ropensci.github.io/NLMR/
65 stars 17 forks source link

Cannot plot list of nlms with `landscapetools::show_landscape` #81

Closed bniebuhr closed 2 years ago

bniebuhr commented 2 years ago

Hi,

I am trying to reproduce the Overview and Tips of the package but I could not plot the landscapes for the chunk "Use matrix of parameter to simulate landscapes". I adapted the example below to make it simpler.

library(NLMR)
library(landscapetools)
library(raster)
library(dplyr)
library(purrr)
library(tibble)

# parameters
param_df <- expand.grid(ncol = 100,
                        nrow = 100,
                        resolution = 100, 
                        autocorr_range = c(10, 100, 500, 1000)) %>% 
  tibble::as_tibble()

# simulated landscapes
nlm_list = param_df %>% pmap(nlm_gaussianfield, user_seed = 123)

# plot
landscapetools::show_landscape(nlm_list)

For the last command, I get the error:

Error: At least one layer must contain all faceting variables: `id`.
* Plot is missing `id`
* Layer 1 is missing `id`
Run `rlang::last_error()` to see where the error occurred.
In addition: Warning message:
`guides(<scale> = FALSE)` is deprecated. Please use `guides(<scale> = "none")` instead. 

If I transform the result into a raster::stack, however, it works, even though the names of the maps/parameters are lost.

I guess the error is with landscapetools::show_landscape, but since the example was for NLMR I am posting it here.

Session Info ```r ─ Session info ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── setting value version R version 4.0.3 (2020-10-10) os Ubuntu 18.04.6 LTS system x86_64, linux-gnu ui RStudio language (EN) collate en_US.UTF-8 ctype en_US.UTF-8 tz Europe/Oslo date 2021-11-30 ─ Packages ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── package * version date lib source assertthat 0.2.1 2019-03-21 [2] CRAN (R 4.0.3) backports 1.2.1 2020-12-09 [2] CRAN (R 4.0.3) cachem 1.0.6 2021-08-19 [2] CRAN (R 4.0.3) callr 3.7.0 2021-04-20 [2] CRAN (R 4.0.3) checkmate 2.0.0 2020-02-06 [2] CRAN (R 4.0.3) class 7.3-19 2021-05-03 [4] CRAN (R 4.0.3) classInt 0.4-3 2020-04-07 [2] CRAN (R 4.0.3) cli 3.0.1 2021-07-17 [2] CRAN (R 4.0.3) codetools 0.2-18 2020-11-04 [4] CRAN (R 4.0.3) colorspace 2.0-2 2021-06-24 [2] CRAN (R 4.0.3) crayon 1.4.1 2021-02-08 [2] CRAN (R 4.0.3) DBI 1.1.1 2021-01-15 [2] CRAN (R 4.0.3) desc 1.4.0 2021-09-28 [2] CRAN (R 4.0.3) devtools 2.4.2 2021-06-07 [2] CRAN (R 4.0.3) digest 0.6.28 2021-09-23 [2] CRAN (R 4.0.3) dplyr * 1.0.7 2021-06-18 [2] CRAN (R 4.0.3) e1071 1.7-9 2021-09-16 [2] CRAN (R 4.0.3) ellipsis 0.3.2 2021-04-29 [1] CRAN (R 4.0.3) fansi 0.5.0 2021-05-25 [2] CRAN (R 4.0.3) farver 2.1.0 2021-02-28 [2] CRAN (R 4.0.3) fastmap 1.1.0 2021-01-25 [2] CRAN (R 4.0.3) fs 1.5.0 2020-07-31 [2] CRAN (R 4.0.3) generics 0.1.0 2020-10-31 [2] CRAN (R 4.0.3) ggplot2 3.3.5 2021-06-25 [2] CRAN (R 4.0.3) glue 1.4.2 2020-08-27 [2] CRAN (R 4.0.3) gtable 0.3.0 2019-03-25 [2] CRAN (R 4.0.3) KernSmooth 2.23-20 2021-05-03 [4] CRAN (R 4.0.5) labeling 0.4.2 2020-10-20 [2] CRAN (R 4.0.3) landscapetools * 0.5.0 2019-02-25 [1] CRAN (R 4.0.3) lattice 0.20-45 2021-09-22 [4] CRAN (R 4.1.1) lifecycle 1.0.1 2021-09-24 [2] CRAN (R 4.0.3) magrittr 2.0.1 2020-11-17 [2] CRAN (R 4.0.3) memoise 2.0.0 2021-01-26 [2] CRAN (R 4.0.3) munsell 0.5.0 2018-06-12 [2] CRAN (R 4.0.3) NLMR * 1.1 2021-09-20 [1] CRAN (R 4.0.3) pillar 1.6.4 2021-10-18 [2] CRAN (R 4.0.3) pkgbuild 1.2.0 2020-12-15 [2] CRAN (R 4.0.3) pkgconfig 2.0.3 2019-09-22 [2] CRAN (R 4.0.3) pkgload 1.2.3 2021-10-13 [2] CRAN (R 4.0.3) prettyunits 1.1.1 2020-01-24 [2] CRAN (R 4.0.3) processx 3.5.2 2021-04-30 [1] CRAN (R 4.0.3) proxy 0.4-26 2021-06-07 [2] CRAN (R 4.0.3) ps 1.6.0 2021-02-28 [2] CRAN (R 4.0.3) purrr * 0.3.4 2020-04-17 [2] CRAN (R 4.0.3) R6 2.5.1 2021-08-19 [2] CRAN (R 4.0.3) RandomFields 3.3.10 2021-09-22 [2] CRAN (R 4.0.3) RandomFieldsUtils 0.5.6 2021-10-21 [2] CRAN (R 4.0.3) raster * 3.5-2 2021-10-11 [2] CRAN (R 4.0.3) Rcpp 1.0.7 2021-07-07 [2] CRAN (R 4.0.3) remotes 2.4.1 2021-09-29 [2] CRAN (R 4.0.3) rgdal 1.5-27 2021-09-16 [2] CRAN (R 4.0.3) rlang 0.4.12 2021-10-18 [2] CRAN (R 4.0.3) rprojroot 2.0.2 2020-11-15 [2] CRAN (R 4.0.3) rstudioapi 0.13 2020-11-12 [2] CRAN (R 4.0.3) scales 1.1.1 2020-05-11 [2] CRAN (R 4.0.3) sessioninfo 1.1.1 2018-11-05 [2] CRAN (R 4.0.3) sf 1.0-3 2021-10-07 [2] CRAN (R 4.0.3) sp * 1.4-6 2021-11-14 [1] CRAN (R 4.0.3) terra 1.4-22 2021-11-24 [1] CRAN (R 4.0.3) testthat 3.1.0 2021-10-04 [2] CRAN (R 4.0.3) tibble * 3.1.5 2021-09-30 [2] CRAN (R 4.0.3) tidyselect 1.1.1 2021-04-30 [2] CRAN (R 4.0.3) units 0.7-2 2021-06-08 [2] CRAN (R 4.0.3) usethis 2.1.0 2021-10-16 [2] CRAN (R 4.0.3) utf8 1.2.2 2021-07-24 [2] CRAN (R 4.0.3) vctrs 0.3.8 2021-04-29 [2] CRAN (R 4.0.3) viridisLite 0.4.0 2021-04-13 [2] CRAN (R 4.0.3) withr 2.4.2 2021-04-18 [2] CRAN (R 4.0.3) [1] /home/NINA.NO/bernardo.brandao/R/x86_64-pc-linux-gnu-library/4.0 [2] /usr/local/lib/R/site-library [3] /usr/lib/R/site-library [4] /usr/lib/R/library ```
marcosci commented 2 years ago

Hi!

Just fixed that, if you install landscapetools now via GitHub it should just work fine!

Cheers Marco