r-mapview图例名称在多行



我试图创建一个多行图例,如在这个传单的例子中所示,但使用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"
)

然而,引入或& lt; 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:/RTMPRtmp6rsB0Pfile2a687e904718/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:/RTMPRtmp6rsB0Pfile2a6843ec14e6/line1<br>line2_layer.fgb', reason #'Invalid argument'
#2: In dir.create(target_dir) :
#  cannot create dir 'libline1<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 . map文件缓存相关的问题。用户和R临时目录文件夹;我删除了。rproj文件的内容。用户共享/笔记本子文件夹,并在tempdir()中清除R临时目录,重新启动RStudio和R后,地图图例被正确创建。感谢@iago在评论中确认样例代码在Linux上工作。

相关内容

  • 没有找到相关文章

最新更新