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
相关产品推荐
相关产品推荐

