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

R语言rayshader包调用plot_map()时出现plotRGB错误求助

解决rayshader包plot_map()报错"unused argument (asp = 1)"的方法

这个错误通常由包版本不兼容或函数冲突导致,以下是几种可行的解决方式:

  • 更新依赖包
    优先尝试更新rayshader及其核心依赖包,版本不匹配是这类报错的常见原因:

    update.packages(c("rayshader", "raster", "ggplot2", "magrittr"))
    

    更新完成后重新运行示例代码,多数情况下能直接解决问题。

  • 绕过plot_map(),用ggplot2手动绘图
    如果更新后仍报错,可以直接使用ggplot2绘制sphere_shade的输出结果,替代plot_map():

    library(rayshader)
    library(ggplot2)
    library(magrittr)
    
    # 数据加载部分保留原代码
    loadzip = tempfile() 
    download.file("https://tylermw.com/data/dem_01.tif.zip", loadzip)
    localtif = raster::raster(unzip(loadzip, "dem_01.tif"))
    unlink(loadzip)
    
    elmat = raster_to_matrix(localtif)
    
    # 生成阴影并转换为ggplot可用格式
    shade_map = elmat %>% sphere_shade(texture = "desert")
    shade_df = as.data.frame(shade_map, xy = TRUE)
    colnames(shade_df) = c("x", "y", "r", "g", "b")
    shade_df$color = rgb(shade_df$r, shade_df$g, shade_df$b)
    
    # 绘制地图
    ggplot(shade_df, aes(x = x, y = y)) +
      geom_raster(aes(fill = color)) +
      scale_fill_identity() +
      coord_fixed(ratio = 1) +
      theme_void()
    
  • 排查函数冲突
    若环境中加载了RStoolbox等包,可能会覆盖raster包的plotRGB函数,导致参数不兼容。可以明确指定调用raster包的函数,或暂时卸载冲突包:

    # 卸载冲突包(以RStoolbox为例)
    detach("package:RStoolbox", unload = TRUE)
    # 重新运行原绘图代码
    elmat %>% sphere_shade(texture = "desert") %>% plot_map()
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.17 09:30:46