You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

geom_sf_interactive()合并数据框时的异常行为问题排查

问题:ggiraph绘制交互式地图时触发gList()错误

操作流程与错误详情

  • 加载.gpkg地理空间数据:
geo_data <- read_sf()
  • 加载Excel属性数据:
participantion_2020_raw <- read_excel()
  • 合并数据并转换为sf对象:
participantion_2020 <- participantion_2020_raw %>%
    left_join(
      geo_data %>% select(-c(2:4)),
      by = join_by(obec_code == IDN4)
    ) %>%
    st_as_sf()
  • 绘制交互式地图时出现错误:
map <- ggplot(participantion_2020) + geom_sf_interactive(aes(fill = votes_percent, tooltip = kraj_code, data_id = kraj_code)) + theme_void() + scale_fill_viridis_c()
girafe(ggobj = map)

错误信息:

Error:
! Problem while converting geom to grob.
ℹ Error occurred in the 1st layer.
Caused by error in `gList()`:
! only 'grobs' allowed in "gList"
Run `rlang::last_trace()` to see where the error occurred.

已确认的现象

  • 直接使用原始geo_data创建交互式地图,ggiraph可正常运行;
  • 所有合并后的数据集,使用geom_sf()绘制非交互式地图均能正常渲染;
  • 调换left_join的参数顺序,将geo_data作为第一个参数时,代码可正常执行:
participantion_2020 <-
    left_join(
      geo_data %>% select(-c(2:4)),
      participantion_2020_raw,
      by = join_by(IDN4 == obec_code)
    ) %>%
    st_as_sf()
  • 但使用相同参数顺序执行full_join时,仍会抛出上述相同错误:
participantion_2020 <-
    full_join(
      geo_data %>% select(-c(2:4)),
      participantion_2020_raw,
      by = join_by(IDN4 == obec_code)
    ) %>%
    st_as_sf()

环境信息

R version 4.2.2 (2022-10-31 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19045)

Matrix products: default

locale:
[1] LC_COLLATE=Slovak_Slovakia.utf8  LC_CTYPE=Slovak_Slovakia.utf8    LC_MONETARY=Slovak_Slovakia.utf8
[4] LC_NUMERIC=C                     LC_TIME=Slovak_Slovakia.utf8    

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

other attached packages:
 [1] spData_2.2.2          ggiraph_0.8.7         stringi_1.7.12        sf_1.0-12             readxl_1.4.2         
 [6] here_1.0.1            shinycssloaders_1.0.0 dataui_0.0.1          bslib_0.4.2           shinyWidgets_0.7.6   
[11] reactablefmtr_2.0.0   reactable_0.4.4       plotly_4.10.1         lubridate_1.9.2       forcats_1.0.0        
[16] stringr_1.5.0         dplyr_1.1.0           purrr_1.0.1           readr_2.1.4           tidyr_1.3.0          
[21] tibble_3.1.8          ggplot2_3.4.2         tidyverse_2.0.0       shinydashboard_0.7.2  shiny_1.7.4           

loaded via a namespace (and not attached):
 [1] httr_1.4.5         sass_0.4.5         jsonlite_1.8.4     viridisLite_0.4.1  sp_1.6-0           cellranger_1.1.0  
 [7] remotes_2.4.2      yaml_2.3.7         lattice_0.20-45    pillar_1.9.0       glue_1.6.2         uuid_1.1-0        
[13] digest_0.6.31      promises_1.2.0.1   colorspace_2.1-0   htmltools_0.5.4    httpuv_1.6.9       spDataLarge_2.0.9 
[19] pkgconfig_2.0.3    xtable_1.8-4       scales_1.2.1       later_1.3.0        tzdb_0.3.0         timechange_0.2.0  
[25] proxy_0.4-27       generics_0.1.3     farver_2.1.1       ellipsis_0.3.2     cachem_1.0.7       pacman_0.5.1      
[31] withr_2.5.0        lazyeval_0.2.2     cli_3.6.0          crayon_1.5.2       magrittr_2.0.3     mime_0.12         
[37] fansi_1.0.4        class_7.3-20       tools_4.2.2        data.table_1.14.8  hms_1.1.3          lifecycle_1.0.3   
[43] munsell_0.5.0      compiler_4.2.2     jquerylib_0.1.4    e1071_1.7-13       systemfonts_1.0.4  rlang_1.1.0       
[49] classInt_0.4-8     units_0.8-1        grid_4.2.2         rstudioapi_0.14    htmlwidgets_1.6.2  crosstalk_1.2.0   
[55] labeling_0.4.2     gtable_0.3.3       curl_5.0.0         DBI_1.1.3          R6_2.5.1           fastmap_1.1.0     
[61] utf8_1.2.3         rprojroot_2.0.3    KernSmooth_2.23-20 Rcpp_1.0.10        vctrs_0.5.2        tidyselect_1.2.0 

推测问题源于数据合并后的结构变化,但无法自行定位调试,尝试多种替代方案均未解决。

内容的提问来源于stack exchange,提问作者sketman

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.25 10:35:16