簡體   English   中英

多行的 r-mapview 圖例名稱

[英]r-mapview legend name in multiple lines

我正在嘗試創建一個多行的圖例,如本傳單示例所示,但使用 mapview 包。

按照上面的例子,這些情況工作正常:


    library(leaflet)
    library(raster)
    library(mapview)
    
    p <- shapefile(system.file("external/lux.shp", package="raster"))
    
    pal <- colorNumeric(
      palette = "Reds",
      domain = p$AREA)
    
    p %>% 
      leaflet() %>% 
      addTiles() %>% 
      addPolygons(stroke=FALSE, color = ~pal(AREA), fillOpacity = 1) %>% 
      addLegend(pal = pal, values = ~AREA, title = "line 1 </br> line 2")
    
    p %>%
      mapview(
        zcol = 'AREA',
        stroke = FALSE,
        alpha = 1,
        layer.name = "line 1"
      )

但是,將 </br> 或 <br> 引入 mapview layer.name 會引入錯誤。


    p %>%
      mapview(
        zcol = 'AREA',
        stroke = FALSE,
        alpha = 1,
        layer.name = "line 1 </br> line 2"
      )
    #Error in validateScalarName(name) : 
    #  Invalid argument 'name' (must be a non-empty character string and contain no '/' or '\')
    #In addition: Warning message:
    #In file.create(to[okay]) :
    #  cannot create file 'C:/RTMP\Rtmp6rsB0P\file2a687e904718/line1</br>line2_layer.fgb', reason #'Invalid argument'


    p %>%
      mapview(
        zcol = 'AREA',
        stroke = FALSE,
        alpha = 1,
        layer.name = "line 1 <br> line 2"
      )
    #Error in normalizePath(path.expand(path), winslash, mustWork) : 
    #  path[1]="lib/line1<br>line2-0.0.1": The filename, directory name, or volume label syntax is #incorrect
    #In addition: Warning messages:
    #1: In file.create(to[okay]) :
    #  cannot create file 'C:/RTMP\Rtmp6rsB0P\file2a6843ec14e6/line1<br>line2_layer.fgb', reason #'Invalid argument'
    #2: In dir.create(target_dir) :
    #  cannot create dir 'lib\line1<br>line2-0.0.1', reason 'Invalid argument'

sessionInfo() 下面

 R version 4.0.3 (2020-10-10) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10 x64 (build 19043) Matrix products: default locale: [1] LC_COLLATE=English_United States.1252 [2] LC_CTYPE=English_United States.1252 [3] LC_MONETARY=English_United States.1252 [4] LC_NUMERIC=C [5] LC_TIME=English_United States.1252 attached base packages: [1] stats graphics grDevices datasets utils [6] methods base other attached packages: [1] mapview_2.10.0 raster_3.1-5 sp_1.4-5 [4] leaflet_2.0.4.1 shiny_1.6.0 loaded via a namespace (and not attached): [1] Rcpp_1.0.4.6 lattice_0.20-41 [3] leaflet.providers_1.9.0 png_0.1-7 [5] class_7.3-17 ps_1.6.0 [7] assertthat_0.2.1 digest_0.6.25 [9] utf8_1.2.1 mime_0.9 [11] R6_2.5.0 reprex_2.0.0 [13] stats4_4.0.3 evaluate_0.14 [15] e1071_1.7-3 highr_0.8 [17] pillar_1.6.0 rlang_0.4.10 [19] rstudioapi_0.13 miniUI_0.1.1.1 [21] callr_3.7.0 jquerylib_0.1.4 [23] rmarkdown_2.9 rgdal_1.5-23 [25] webshot_0.5.2 htmlwidgets_1.5.1 [27] munsell_0.5.0 compiler_4.0.3 [29] httpuv_1.6.1 xfun_0.24 [31] pkgconfig_2.0.3 base64enc_0.1-3 [33] clipr_0.7.0 htmltools_0.5.1.1 [35] tidyselect_1.1.0 tibble_3.1.1 [37] codetools_0.2-16 fansi_0.4.2 [39] dplyr_1.0.5 crayon_1.4.1 [41] withr_2.4.2 later_1.0.0 [43] sf_0.9-8 grid_4.0.3 [45] jsonlite_1.6.1 satellite_1.0.2 [47] xtable_1.8-4 lifecycle_1.0.0 [49] DBI_1.1.1 magrittr_2.0.1 [51] units_0.6-6 scales_1.1.0 [53] KernSmooth_2.23-17 cli_2.4.0 [55] cachem_1.0.5 farver_2.0.3 [57] renv_0.13.2 fs_1.5.0 [59] promises_1.1.0 bslib_0.2.5.1 [61] generics_0.0.2 ellipsis_0.3.1 [63] vctrs_0.3.7 RColorBrewer_1.1-2 [65] tools_4.0.3 leafem_0.1.3 [67] glue_1.4.2 purrr_0.3.4 [69] crosstalk_1.1.0.1 processx_3.5.2 [71] fastmap_1.1.0 yaml_2.2.1 [73] colorspace_1.4-1 classInt_0.4-3 [75] knitr_1.28 sass_0.4.0

關於如何解決這個問題的任何建議?

看起來這是一個與緩存 .Rproj.user 和 R 臨時目錄文件夾中的地圖文件相關的問題; 我刪除了 .Rproj.user shared/notebooks 子文件夾的內容並清除了 tempdir() 中的 R 臨時目錄,在重新啟動 RStudio 和 R 后,正確創建了地圖圖例。 感謝 @iago 在評論中確認示例代碼可在 Linux 上運行。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM