Cirad-ASTRE / mapMCDA

Produce an epidemiological risk map by weighting multiple risk factors
https://umr-astre.pages.mia.inra.fr/mapMCDA/
1 stars 2 forks source link

Error in risk by epidemiological unit plot: "'from' must be a finite number" #32

Closed famuvie closed 5 years ago

famuvie commented 5 years ago

This is caused by small polygons (epidemiological units) that do not cover any of the raster cell centres of the risk map. For instance, small islands.


library(mapMCDA)
library(raster)
#> Loading required package: sp
## 10 x 10 raster with sequential values
r <- raster(xmn=-110, xmx=-90, ymn=40, ymx=60, nrow = 10, ncol = 10)
r <- setValues(r, seq.int(ncell(r)))

## polygons covering the region by squares of 2x2 pixels
r0 <- r
res(r0) <- 2*res(r)
epiunits <- as(r0, "SpatialPolygons")
epi_ext <- raster::bind(raster::shift(epiunits[c(1, 6)], x = -5), epiunits)

## Problematic situation: one or more polygons off (islands or very small units)
plot(r)
plot(epi_ext, add = TRUE)


res <- risk_unit(r, epi_ext)

## There are a missing value for those polygons. That's fine.
head(res)
#> [1]   NA   NA  6.5  8.5 10.5 12.5

## But they break the plot:
risk_plot(epi_ext, res, n = 5)
#> Error in seq.default(from = rv[1], to = rv[2], length = n + 1): 'from' must be a finite number

Created on 2019-04-12 by the reprex package (v0.2.1)