knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

Package of functions of the Laboratory of Innovation in Health (InnovaLab) of the Institute of Tropical Medicine "Alexander von Humboldt", Universidad Peruana Cayetano Heredia.

🟣 1. Requeriments

library(innovar)
library(sf)
library(rgee)
library(tidyverse)
library(viridis)
library(cowplot)
library(mapview)
ee_Initialize() # edit
── rgee 1.1.2.9000 ──────────────────────── earthengine-api 0.1.297 ──
 ✓ user: not_defined
 ✓ Initializing Google Earth Engine:  DONE!
 ✓ Earth Engine account: users/antonybarja8
──────────────────────────────────────────────────────────────────────

🟣 2. Vector layer reading of Peru

library(innovar)
library(mapview)
library(tidyverse)
data("Peru")
peru.region <- Peru %>%
  dplyr::group_by(dep) %>%
  summarise()

glimpse(peru.region)

🟣 3. Exploration Peru map

mapview(peru.region,legend = NULL)

🟣 4. Transformation of sf object to a feature collection

peru.ee <- peru.region %>%
  pol_as_ee(
    id = c("dep"),
    simplify = 100
    )

🟣 5. Processing data with innovar

peru.ndvi <- peru.ee %>%
  get_vegetation(
    from = "2018-01-01",
    to = "2019-12-31",
    band = "NDVI",
    fun = "mean")

peru.def <- peru.ee %>%
  get_def(
    from = "2018-02-01",
    to = "2019-12-31"
    )

peru.pr <- peru.ee %>%
  get_climate(
    from = "2018-02-01",
    to = "2019-12-31",
    by = "month",
    band = "pr",
    fun = "mean"
    )
[1] "Extracting information [0/25]..."
[1] "Extracting information [0/25]..."
[1] "Extracting information [0/25]..."

🟣 6. Processing data for mapping

peru.def <- read_rds("data")[[1]]
peru.ndvi <- read_rds("data")[[2]]
peru.pr <- read_rds("data")[[3]]
peru.ndvi.sf <- inner_join(peru.region,peru.ndvi,"dep")
peru.pr.sf <- inner_join(peru.region,peru.pr ,"dep")
peru.def.sf <- inner_join(peru.region,peru.def,"dep")

🟣 7. Exploration data

# peru.ndvi.sf
glimpse(peru.ndvi.sf)
# peru.pr.sf
glimpse(peru.pr.sf)
# peru.def.sf
glimpse(peru.def.sf)

🟣 8. Exploration peru.ndvi.sf map

mapview(
  peru.ndvi.sf,
  zcol="NDVI2018-01",
  layer.name = "NDVI-2018-01"
  )

🟣 9. Exploration peru.pr.sf map

mapview(
  peru.pr.sf,
  zcol="pr2018-02",
  layer.name = "pr-2018-02"
  )

🟣 10. Exploration peru.def.sf map

mapview(
  peru.def.sf,
  zcol="Adef_2018",
  layer.name = "def-2018"
  )

🟣 11. Mapping climate variables with the innovar theme

pr.plot <- peru.pr.sf %>%
  ggplot() +
  geom_sf(aes(fill=`pr2019-01`)) +
  scale_fill_innova(discrete = FALSE,name="Precipitation") +
  theme_bw()
ndvi.plot<- peru.ndvi.sf %>%
  ggplot() +
  geom_sf(aes(fill=`NDVI2019-01`)) +
  scale_fill_innova(discrete = FALSE,name="NDVI") +
  theme_bw()
def.plot <-  peru.def.sf %>%
  ggplot() +
  geom_sf(aes(fill=Adef_2019)) +
  scale_fill_innova(discrete = FALSE,name="Deforestation") +
  theme_bw()

🟣 12. Final plot

pr.plot
ndvi.plot
def.plot


healthinnovation/lis documentation built on June 19, 2024, 6:06 a.m.