r - 在地图上绘制 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)
解决方案
推荐阅读
- java - 为什么会出现 JDOUserException?
- python - 我在分配错误之前得到了引用
- postgresql - 故障排除错误:最后一个预期列之后的额外数据
- javascript - Fullcalendar 在事件下方添加一些元素
- c++ - 使用 Visual Studio Force 时的智能感知错误包括
- security - Terraform:您如何检查敏感数据?
- excel - VBA - 多个范围的 Excel 到 powerpoint 崩溃
- c# - 尝试将充满 1 和 0(二进制)的数组转换为字符串,然后在 Unity 中转换为 int
- dialog - 如何根据数组中的项目显示 Vuetify 对话框内容
- google-chrome - IONIC 5:仅在手机的 chrome 浏览器中打开外部 URL