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

如何使用ggplot2为SpatRaster可视化添加底图?求技术方案

求助:用ggplot2+terra给SpatRaster加底图失败,求解决办法

我想结合ggplot2和terra包,给我的SpatRaster图层加上底图,但试了好几次都没成功,希望有人能帮忙解决这个问题。

已尝试的代码

library(basemaps)
library(terra)
library(rasterVis)

set_defaults(Yiel_total , map_service = "esri" , map_type = "world_hillshade")
x <- basemap_magic(Yiel_total , map_service = "esri" , map_type = "world_hillshade")
#用Yiel_total匹配底图范围

数据说明

用到的SpatRaster数据为Yield_total

当前ggplot可视化代码

Yield <- rast("Yield_total")
Yield_Tot_6 <- gplot(Yield ) + geom_tile(aes(fill = value)) + ggtitle("")+
  theme(panel.spacing.x=unit(0,"lines"), axis.title.x = element_blank(), axis.text = element_blank(), axis.ticks = element_blank(),
        axis.title.y = element_blank(),plot.title = element_text(hjust = 0.5, size = 18, face = "bold"),strip.background = element_blank(),
        strip.text = element_text(size = 14, color = "black", face = "bold"),legend.text = element_text(size = 14, face = "bold"),
        legend.title = element_text(hjust = 0.1, size = 16, face = "bold"), panel.background = element_blank()) +
  guides(fill = guide_colourbar(title = "Relative yield",title.hjust = 0.5, barheight = 15, barwidth = 2))+ 
  #basemap_magic(Yield_0.5_6, map_service = "esri" , map_type = "world_hillshade")+
  
  facet_wrap(~ variable, ncol = 3 ) +
  scale_fill_gradient(limits = c(0.01,0.88),low = 'red', high = 'dark green', na.value = "grey93", breaks = c(0.02,0.20, 0.40, 0.60,0.75, 0.87))

Yield_Tot_6

需求:在上述ggplot绘制的SpatRaster可视化中,成功添加底图。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.11 00:10:49