首页 > 解决方案 > 在地图上绘制 gam 空间估计

问题描述

我已经使用以下代码导入了意大利地图:

library(ggplot2)
library(mgcv) 
library(ggmap) 
Country <- "Italy"

Get_Map_Country <-
  get_map(
      location = Country
    , zoom = 6
    , scale = "auto"
    , maptype = "satellite"
    , messaging = FALSE
    , urlonly = FALSE
    , filename = "ggmapTemp"
    , crop = TRUE
    , color = "color"
    , source = "google"
    , api_key
    )

Country1 <-
  ggmap(
      ggmap = Get_Map_Country
    , extent = "panel"
  #  , base_layer
    , maprange = FALSE
    , legend = "right"
    , padding = 0.02
    , darken = c(0, "black")
    )

此外,我拟合了一个 gam 模型,其中假设响应为泊松,预测变量为经度和纬度。

mod1 <- gam(Value ~ s(Longitudine, Latitudine), data = data2017, family = "poisson")

现在,如何将结果叠加到上面的 ggmap 上?例如,我想获得类似的东西:

在此处输入图像描述

通过使用与 github 的 devtools 一起安装的“mfasiolo/mgcViz”包获得

library(devtools) 
install_github("mfasiolo/mgcViz")
library(mgcViz) 

b <- getViz(mod1)

pl <- plot(sm(b, 1)) + l_fitRaster() + l_fitContour() 
pl

但好看(用于出版),在意大利地图上略显透明。如果有人知道获得这个的方法,我将非常感激。

我对不同但有意义的解决方案持开放态度。提前致谢。

简单的可重现示例

> y <- c(10,   1,   2,   2,   2,   0,  19,   3,  2,   1,   7,  16,   5, 
> 13,  81,   1,   9,  96,   2,   9,  3,   4,   0, 1,  12)
> 
> long <- seq(9, 13, length.out = 25) 
> 
> lat <- seq(38, 43, length.out = 25) 
> 
> mod1 <- gam(y ~ s(long, lat, k = 3), family = "poisson")
#Now, I need not overlay Country1 and something like plot(mod1) 

标签: rspatialggmappoissongam

解决方案


推荐阅读