0

I am creating a plot based on INLA predictions. Everything works perfectly for the modelling, but for the plot,the legend on the graph are points (like https://gis.stackexchange.com/questions/350918/how-do-i-reverse-spplot-colour-key-so-the-values-are-decreasing) rather than a scale (like here http://www.nickeubank.com/wp-content/uploads/2015/10/RGIS3_MakingMaps_part1_mappingVectorData.html):

enter image description here

And here is the code that I would like to change. I guess there is a problem of factor (R spplot: colorbar rather than legend for SpatialPoint data, spplot issue with legend range and colors distribution) but I cannot understand how/what to change:

m_grid <- inla(formWITHOUT, data = inla.stack.data(region.stack.predGrid, spde = inlaSetting$region.spde),
          family = "gamma",
          control.predictor = list(A = inla.stack.A(region.stack.predGrid), compute = TRUE, link=1),
          control.compute = list(cpo = TRUE, dic = TRUE),
          control.family=list(link="default"))

summary(m_grid)

index.pred <- inla.stack.index(region.stack.predGrid, "region.pred")$data

region.grid_sf$Sbiomass <- m_grid$summary.fitted.values[index.pred, "mean"]
region.grid_sf$Sbiomass_sd <- m_grid$summary.fitted.values[index.pred, "sd"]

my.palette <- brewer.pal(n = 7, name = "OrRd")

par(mar = c(0,0,0,0))
spplot(region.grid_sf, c("Sbiomass"), col.regions = my.palette, col = "transparent")

Thanks in advance for any tips !

CharlotteS.
  • 355
  • 1
  • 12
  • It seems (https://edzer.github.io/sp/#using-lattice-plot-spplot) that the legend will use point symbols for spatial points, and the desired colour bar for rasters or polygons. You could try to convert your point data to raster (e. g. via kriging) or polygons (e.g. Voronoi or rectangular grid). – I_O Jan 10 '23 at 21:15
  • 1
    actually the answer was simpler that I thought: add "colorkey =T" as parameter :D – CharlotteS. Jan 11 '23 at 15:35
  • Could you make this an answer to your own question and mark it as "accepted answer" (so future users can identify it as a solved problem)? Thank you! :-) – I_O Jan 11 '23 at 16:14

1 Answers1

0

I finally found the answer:

cuts <- c(0,5000,10000,15000,20000,25000,30000)

spplot(region.grid_sf, 
       c("Sbiomass"), 
       col.regions = my.palette, 
       col = "transparent",
       key.space = list(x=0.1,y=0.3),
       colorkey  =T,
       cuts = cuts, 
       cex = 2, 
       pch = 22)
CharlotteS.
  • 355
  • 1
  • 12