diff --git a/.gitignore b/.gitignore index ecf3edb8b505acc92f08a8cf19451cb1bb4d27b3..9c15171ab5411096d3531c60ba538ff5733b6324 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .drake .Rhistory dave's_scratchpad.R +plan_execute.R diff --git a/src/asf_challenge.Rmd b/src/asf_challenge.Rmd index ea3d19075d76dba2b092fc3603013017180a76d0..0dffe9d5b76237664c62447ed73beafe1f885293 100644 --- a/src/asf_challenge.Rmd +++ b/src/asf_challenge.Rmd @@ -48,7 +48,12 @@ loadd( data_structure, pig_sites, outbreaks, - animal_movements + animal_movements, + adminPigSiteMap, + proportionAgroCoverMap, + proportionForestCoverMap, + movementFileName, + movementAnimation ) ``` @@ -97,21 +102,9 @@ supposed to be an island. ```{r map-admin, fig.cap = cap} cap <- "Administrative divisions of the dummy territory and pig sites. Observed cases are highlighted in dark red." -tm_shape(admin) + - tm_graticules(col = "lightgrey") + - tm_polygons() + - tm_compass(type = "8star", position = c("left", "top")) + - tm_scale_bar(breaks = c(0, 100, 200), text.size = 1) + - tm_layout(bg.color = "lightblue") + - tm_shape(pig_sites) + - tm_dots() + - tm_shape(outbreaks) + - tm_dots(size = .1, col = "darkred") - +adminPigSiteMap ``` - - ### Land cover Figure \@ref(fig:land-cover) shows a simplified version of the @@ -139,38 +132,15 @@ Here land cover proportions of forest and agriculture are preressented on such a ```{r hex-land-cover-agri, message = FALSE, fig.cap = cap} cap <- "Proportional cover of agriculture on hexagonal grid." - -tm_shape(admin) + - tm_polygons() + - tm_shape(hex) + - tm_polygons(col = "pAgricultural") - +proportionAgroCoverMap ``` - ```{r hex-land-cover-forest, message = FALSE, fig.cap = cap} cap <- "Proportional cover of forest on hexagonal grid, with detected cases among pig farms and wild boar." - -tm_shape(admin) + - tm_polygons() + - tm_graticules(col = "lightgrey") + - tm_layout(bg.color = "lightblue") + - tm_shape(hex) + - tm_polygons(col = "pForest", lwd=0.2, border.col="grey", palette=get_brewer_pal("Greens", n = 10, plot=FALSE)) + - tm_shape(pig_sites) + - tm_dots() + - tm_shape(outbreaks[outbreaks$HOST=="wild boar",]) + - tm_dots(size = .2, col = "orange") + - tm_shape(outbreaks[outbreaks$HOST=="pig herd",]) + - tm_dots(size = .2, col = "red") + - tm_add_legend(type="symbol", labels=c("pig herd","wild boar"), col=c("red", "orange"), border.col=c("red", "orange"), title="Cases") + - tm_scale_bar(breaks = c(0, 50, 100, 150), text.size = 1, position = c("left", "top")) - +proportionForestCoverMap ``` - - #### Coordinate reference systems The coordinate system used for shapefile Island_ADMIN.shp is ```{r map-admin-crs} @@ -186,17 +156,9 @@ the official projection in France. Note, the units are in meters. ### Animal movements -```{r eval = FALSE} -## This is useless -tm_shape(admin) + - tm_graticules(col = "lightgrey") + - tm_polygons() + - tm_layout(bg.color = "lightblue") + - tm_shape(pig_sites) + - tm_dots() + - tm_shape(animal_movements) + - tm_lines(alpha = .3) -``` +{ width=60% } + + \clearpage diff --git a/src/plan.R b/src/plan.R index 10cbf687d8a973aabf67d5f723545d4828028922..59d5767c69af0e6caa49e9803830f49777fbd153 100644 --- a/src/plan.R +++ b/src/plan.R @@ -53,17 +53,75 @@ plan <- drake_plan( ## (NE sites, see doc (?)) ## 18794 lines removed. Produced invalid lines. filter(source != dest) %>% + ## Add a column to provide title when using tmap_animation + mutate(day4display=paste("Day", stringr::str_pad(date, nchar(max(date)), pad="0"))) %>% ## Put source and dest as the first two cols. ## Necessary to match with ID in pig_sites - select(source, dest, everything()), + select(source, dest, everything()), + ## %>% + ## FOR RAPID COMPILATION WHILE DEBUGGING - REMOVE WHEN DEBUGGED + ## filter(date < 10), zones = pig_sites), #### PRE-COMPUTE COMPLICATED FIGURES #### data_structure = plot_data_structure(fname = here("src/data_structure.yml")), ## Distance matrix for pigs - distMatPigs = st_distance(pig_sites), - + distMatPigs = st_distance(pig_sites), + + ## Some constants + nPigSites = nrow(pig_sites), + + ## Animation + movementFileName = file_out(here("animations/animal_moves_by_day.gif")), + + movementAnimation = tmap_animation(tm_shape(admin) + + tm_graticules(col = "lightgrey") + + tm_polygons() + + tm_shape(pig_sites) + + tm_dots(alpha = .3) + # tm_shape(littleAM) + ## + tm_shape(animal_movements) + + tm_lines(alpha=0.5) + + tm_facets(along = "day4display", free.coords=FALSE) + + tm_layout(bg.color = "lightblue"), + filename=(movementFileName), ## file_out + width=2000, delay=100, restart.delay = 300), # loop=FALSE, + + + ## Map of administrative areas with pigsites and first cases + adminPigSiteMap = tm_shape(admin) + + tm_graticules(col = "lightgrey") + + tm_polygons() + + tm_compass(type = "8star", position = c("left", "top")) + + tm_scale_bar(breaks = c(0, 100, 200), text.size = 1) + + tm_layout(bg.color = "lightblue") + + tm_shape(pig_sites) + + tm_dots() + + tm_shape(outbreaks) + + tm_dots(size = .1, col = "darkred"), + + ## Map of proportional agriculture cover + proportionAgroCoverMap = tm_shape(admin) + + tm_polygons() + + tm_shape(hex) + + tm_polygons(col = "pAgricultural"), + + ## Map of proportional forest cover + proportionForestCoverMap = tm_shape(admin) + + tm_polygons() + + tm_graticules(col = "lightgrey") + + tm_layout(bg.color = "lightblue") + + tm_shape(hex) + + tm_polygons(col = "pForest", lwd=0.2, border.col="grey", palette=get_brewer_pal("Greens", n = 10, plot=FALSE)) + + tm_shape(pig_sites) + + tm_dots() + + tm_shape(outbreaks[outbreaks$HOST=="wild boar",]) + + tm_dots(size = .2, col = "orange") + + tm_shape(outbreaks[outbreaks$HOST=="pig herd",]) + + tm_dots(size = .2, col = "red") + + tm_add_legend(type="symbol", labels=c("pig herd","wild boar"), col=c("red", "orange"), border.col=c("red", "orange"), title="Cases") + + tm_scale_bar(breaks = c(0, 50, 100, 150), text.size = 1, position = c("left", "top")), + #### REPORTS #### report = rmarkdown::render( knitr_in(here("src/asf_challenge.Rmd")),