10.4 Mapping
We can do for every year we have data:
<- inla.stack.index(stack = stk.full, tag = "pred")$data
index
<- data.frame(dp)
dp names(dp) <- c("x", "y", "time") # time is new
$pred_mean <- res$summary.fitted.values[index, "mean"]
dp$pred_ll <- res$summary.fitted.values[index, "0.025quant"]
dp$pred_ul <- res$summary.fitted.values[index, "0.975quant"]
dp
library(reshape2) # I was to lazy
<- melt(dp,
dpm id.vars = c("x", "y", "time"),
measure.vars = c("pred_mean", "pred_ll", "pred_ul")
)
ggplot(m) + geom_sf() + coord_sf(datum = NA) +
geom_tile(data = dpm, aes(x = x, y = y, fill = value)) +
labs(x = "", y = "") +
facet_wrap(variable ~ time) +
scale_fill_viridis("PM2.5") +
theme_bw()