0

I have been trying to create a daily kriged map of the 24-hour PM2.5 values available through a dataset using R. It should give 61 maps as an output. Through the code below I was able to get the data points for the 61 maps. However, it is showing only one map in leaflet format. I am not sure where I am going wrong. Any help is highly appreciated. Thank you.

startdate <- as.Date("2020-09-01")
enddate <- as.Date("2020-10-31")

dates <- seq(enddate , startdate , by = -1)

maps <- list()

for (i in seq_along(dates)) {
  currentd <- subset(lab3eleutm, as.Date(date) == dates[i])
  
  krigelab <- fitme(pm25 ~ 1 + Matern(1|X+Y),
                    data = lab31utm,
                    fixed=list(nu=0.5))
  
  predslab <- predict(krigelab,
                     ` newdata=pred3utm %>%
            `            st_drop_geometry(), 
                      variances=list(linPred=TRUE,predVar=TRUE))
  
  predele <- tibble(pred3utm,
                    first_max_value_pred = predslab[,1],
                    first_max_value_var = attributes(predslab)$predVar) %>%
    st_as_sf(coords=c("X","Y"),
             crs=st_crs(lab3eleutm)) 
  
  predrast3 <- predele %>%
    st_transform(st_crs(lab3eleutm)) %>%
    st_rasterize(template = lab3gridraster)
  
  finallab3  <- tm_shape(predrast3) +
    tm_raster() +
    tm_shape(lab3eleutm) +
    tm_dots(col = "pm25") +
    tm_layout(frame = FALSE)
  
  maps[[i]] <- finallab3

enter image description here

dww
  • 30,425
  • 5
  • 68
  • 111
Dr Jyothi
  • 1
  • 1
  • Welcome to Stack Overflow. You did not provide all the code necessary for a minimum, reproducible example. For example, your for loop is not complete. Please read this and edit your question as necessary. https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – John Polo Mar 05 '23 at 02:21

0 Answers0