edzer / sdsr

Spatial Data Science: With Applications in R (source files)
https://r-spatial.org/book
Other
242 stars 91 forks source link

plot error in 7.4.2 Example: Bristol origin-destination datacube #81

Closed williamlai2 closed 1 year ago

williamlai2 commented 2 years ago

Hi, there is an error with the last line here. Not sure what the correct code should be.

In this section: 7.4.2 Example: Bristol origin-destination datacube

library(units)
a = set_units(st_area(st_as_sf(o)), km^2)
o$sum_km = o$sum / a
d$sum_km = d$sum / a
od = c(o["sum_km"], d["sum_km"], along = list(od = c("origin", "destination")))
plot(od, logz = TRUE)

Error in Ops.units(at, br[1]) : both operands of the expression should be "units" objects

> sessionInfo()
R version 4.0.3 (2020-10-10)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.6 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.7.1
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.7.1

locale:
 [1] LC_CTYPE=C.UTF-8       LC_NUMERIC=C           LC_TIME=C.UTF-8        LC_COLLATE=C.UTF-8     LC_MONETARY=C.UTF-8   
 [6] LC_MESSAGES=C.UTF-8    LC_PAPER=C.UTF-8       LC_NAME=C              LC_ADDRESS=C           LC_TELEPHONE=C        
[11] LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C   

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

other attached packages:
 [1] units_0.7-2       spDataLarge_2.0.6 xts_0.12.1        zoo_1.8-8         spacetime_1.2-8   stars_0.5-2       abind_1.4-5      
 [8] forcats_0.5.0     stringr_1.4.0     dplyr_1.0.8       purrr_0.3.4       readr_2.0.2       tidyr_1.2.0       tibble_3.1.6     
[15] ggplot2_3.3.5     tidyverse_1.3.0   sf_1.0-8         

loaded via a namespace (and not attached):
 [1] httr_1.4.2         jsonlite_1.7.2     modelr_0.1.8       assertthat_0.2.1   sp_1.4-5           cellranger_1.1.0   yaml_2.2.1        
 [8] pillar_1.6.4       backports_1.2.1    lattice_0.20-41    glue_1.6.2         digest_0.6.27      rvest_1.0.1        colorspace_2.0-2  
[15] htmltools_0.5.2    pkgconfig_2.0.3    broom_0.8.0        haven_2.3.1        s2_1.1.0           intervals_0.15.2   scales_1.2.0      
[22] tzdb_0.1.2         proxy_0.4-26       generics_0.1.2     ellipsis_0.3.2     withr_2.5.0        cli_3.3.0          magrittr_2.0.1    
[29] crayon_1.4.2       readxl_1.3.1       evaluate_0.14      fs_1.5.0           fansi_0.5.0        MASS_7.3-53        xml2_1.3.2        
[36] lwgeom_0.2-5       class_7.3-17       tools_4.0.3        hms_0.5.3          lifecycle_1.0.1    munsell_0.5.0      reprex_0.3.0      
[43] packrat_0.7.0      compiler_4.0.3     e1071_1.7-9        rlang_1.0.2        classInt_0.4-3     grid_4.0.3         rstudioapi_0.13   
[50] cubelyr_1.0.1      rmarkdown_2.11     wk_0.6.0           gtable_0.3.0       DBI_1.1.1          R6_2.5.1           lubridate_1.7.10  
[57] knitr_1.34         fastmap_1.1.0      utf8_1.2.2         KernSmooth_2.23-17 stringi_1.7.4      parallel_4.0.3     Rcpp_1.0.7        
[64] vctrs_0.3.8        dbplyr_2.1.1       tidyselect_1.1.2   xfun_0.25  
edzer commented 2 years ago

Works for me with

> sessionInfo()
R version 4.2.1 (2022-06-23)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 22.04.1 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.20.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_GB.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_GB.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_GB.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C       

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

other attached packages:
[1] units_0.8-0       tidyr_1.2.0       dplyr_1.0.9       stars_0.5-7      
[5] sf_1.0-9          abind_1.4-5       spDataLarge_2.0.1

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.9         compiler_4.2.1     pillar_1.8.1       class_7.3-20      
 [5] tools_4.2.1        lifecycle_1.0.3    tibble_3.1.8       lattice_0.20-45   
 [9] pkgconfig_2.0.3    rlang_1.0.6        DBI_1.1.3          cli_3.4.0.9000    
[13] parallel_4.2.1     e1071_1.7-11       terra_1.6-29       s2_1.1.0          
[17] withr_2.5.0        raster_3.6-3       generics_0.1.3     vctrs_0.4.1       
[21] classInt_0.4-8     grid_4.2.1         tidyselect_1.2.0   glue_1.6.2        
[25] R6_2.5.1           fansi_1.0.3        sp_1.5-0           purrr_0.3.5       
[29] magrittr_2.0.3     codetools_0.2-18   ellipsis_0.3.2     assertthat_0.2.1  
[33] KernSmooth_2.23-20 utf8_1.2.2         proxy_0.4-27       wk_0.6.0          
[37] lwgeom_0.2-9