Skip to contents

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

── 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

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

glimpse(peru.region)
#> Rows: 25
#> Columns: 2
#> $ dep      <chr> "AMAZONAS", "ANCASH", "APURIMAC", "AREQUIPA", "AYACUCHO", "CA…
#> $ geometry <GEOMETRY [Β°]> POLYGON ((-77.77036 -5.7881..., POLYGON ((-77.32594 …

🟣 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.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)
#> Rows: 25
#> Columns: 26
#> $ dep           <chr> "AMAZONAS", "ANCASH", "APURIMAC", "AREQUIPA", "AYACUCHO"…
#> $ geometry      <GEOMETRY [Β°]> POLYGON ((-77.77036 -5.7881..., POLYGON ((-77.3…
#> $ `NDVI2018-01` <dbl> 0.7618698, 0.3541663, 0.5611348, 0.1752459, 0.3877662, 0…
#> $ `NDVI2018-02` <dbl> 0.7448193, 0.3682141, 0.5148198, 0.1865946, 0.4088631, 0…
#> $ `NDVI2018-03` <dbl> 0.8029652, 0.3227369, 0.4254005, 0.1378987, 0.2981394, 0…
#> $ `NDVI2018-04` <dbl> 0.7347934, 0.3371762, 0.4594330, 0.1448148, 0.3126478, 0…
#> $ `NDVI2018-05` <dbl> 0.7689978, 0.3401211, 0.4600456, 0.1549041, 0.3284372, 0…
#> $ `NDVI2018-06` <dbl> 0.7269479, 0.3541572, 0.5168134, 0.2049914, 0.4187075, 0…
#> $ `NDVI2018-07` <dbl> 0.8020183, 0.4326799, 0.5730193, 0.2262396, 0.4889410, 0…
#> $ `NDVI2018-08` <dbl> 0.8070872, 0.4148736, 0.5476173, 0.2076000, 0.4534685, 0…
#> $ `NDVI2018-09` <dbl> 0.8101346, 0.4133105, 0.5284252, 0.1909058, 0.4427989, 0…
#> $ `NDVI2018-10` <dbl> 0.8170537, 0.3509110, 0.4392075, 0.1657147, 0.3792495, 0…
#> $ `NDVI2018-11` <dbl> 0.8242056, 0.3235377, 0.3881956, 0.1561938, 0.3439301, 0…
#> $ `NDVI2018-12` <dbl> 0.7941804, 0.2909917, 0.3439517, 0.1461801, 0.3028986, 0…
#> $ `NDVI2019-01` <dbl> 0.7721825, 0.3645026, 0.5550635, 0.2020809, 0.4484064, 0…
#> $ `NDVI2019-02` <dbl> 0.7961381, 0.2789325, 0.3385547, 0.1465387, 0.2906443, 0…
#> $ `NDVI2019-03` <dbl> 0.7618869, 0.2484661, 0.3389919, 0.1420803, 0.2598204, 0…
#> $ `NDVI2019-04` <dbl> 0.7789701, 0.2859070, 0.4143425, 0.1487514, 0.2911723, 0…
#> $ `NDVI2019-05` <dbl> 0.7956927, 0.3121799, 0.4847778, 0.1496801, 0.3300418, 0…
#> $ `NDVI2019-06` <dbl> 0.8032700, 0.4255341, 0.5458136, 0.1922310, 0.4524076, 0…
#> $ `NDVI2019-07` <dbl> 0.7483550, 0.4138269, 0.5001589, 0.1694564, 0.4188638, 0…
#> $ `NDVI2019-08` <dbl> 0.8106696, 0.3689997, 0.4170743, 0.1537410, 0.3577194, 0…
#> $ `NDVI2019-09` <dbl> 0.7802994, 0.3259332, 0.3905960, 0.1502291, 0.3389899, 0…
#> $ `NDVI2019-10` <dbl> 0.8026335, 0.3055392, 0.3811376, 0.1417420, 0.3191863, 0…
#> $ `NDVI2019-11` <dbl> 0.7666535, 0.2646288, 0.3565503, 0.1348875, 0.2862325, 0…
#> $ `NDVI2019-12` <dbl> 0.7294221, 0.2311107, 0.3716801, 0.1345843, 0.2672917, 0…
# peru.pr.sf
glimpse(peru.pr.sf)
#> Rows: 25
#> Columns: 25
#> $ dep         <chr> "AMAZONAS", "ANCASH", "APURIMAC", "AREQUIPA", "AYACUCHO", …
#> $ geometry    <GEOMETRY [Β°]> POLYGON ((-77.77036 -5.7881..., POLYGON ((-77.325…
#> $ `pr2018-02` <dbl> 87.0465834, 73.7189378, 207.3803203, 69.8458789, 168.25667…
#> $ `pr2018-03` <dbl> 107.5493579, 96.1502156, 186.2385343, 71.8486227, 147.8381…
#> $ `pr2018-04` <dbl> 101.7872776, 67.3360464, 63.3649774, 19.4575723, 83.356019…
#> $ `pr2018-05` <dbl> 148.628940, 33.222182, 19.758310, 6.849864, 46.346711, 60.…
#> $ `pr2018-06` <dbl> 358.2580687, 15.1085579, 44.5938228, 5.8503115, 77.7538876…
#> $ `pr2018-07` <dbl> 192.5851479, 19.2629212, 29.5842716, 15.5349233, 65.273883…
#> $ `pr2018-08` <dbl> 112.383666, 18.410591, 25.218101, 2.588099, 38.385395, 35.…
#> $ `pr2018-09` <dbl> 69.6499857, 31.7195417, 46.7435603, 8.7868353, 123.9690801…
#> $ `pr2018-10` <dbl> 322.719653, 94.278051, 88.712101, 18.894828, 95.677431, 56…
#> $ `pr2018-11` <dbl> 203.290611, 70.305666, 66.502518, 12.946156, 59.295880, 15…
#> $ `pr2018-12` <dbl> 180.3597326, 52.6465738, 97.7328550, 31.5980717, 67.998178…
#> $ `pr2019-01` <dbl> 210.409459, 85.551838, 209.236384, 89.596080, 178.053166, …
#> $ `pr2019-02` <dbl> 175.003831, 105.491556, 233.468952, 95.274428, 202.714531,…
#> $ `pr2019-03` <dbl> 234.7843341, 127.5974202, 191.6842305, 71.7260920, 176.660…
#> $ `pr2019-04` <dbl> 212.2099943, 49.7779733, 56.8066528, 18.7805499, 45.388637…
#> $ `pr2019-05` <dbl> 206.5401270, 13.4165981, 13.4748249, 3.3185407, 16.5801441…
#> $ `pr2019-06` <dbl> 202.3198751, 3.2593835, 3.9852015, 0.4747129, 4.7296860, 4…
#> $ `pr2019-07` <dbl> 201.3254233, 4.1375128, 8.2567924, 1.3395482, 8.5875052, 4…
#> $ `pr2019-08` <dbl> 101.9690712, 1.1197007, 6.4958554, 0.6039247, 4.1187032, 2…
#> $ `pr2019-09` <dbl> 111.7446258, 14.0917587, 20.8372144, 5.5246722, 25.3573550…
#> $ `pr2019-10` <dbl> 157.9943562, 39.6498518, 33.1662222, 4.9280120, 25.2767541…
#> $ `pr2019-11` <dbl> 214.094409, 60.600451, 96.806961, 18.399584, 56.988385, 11…
#> $ `pr2019-12` <dbl> 246.4900612, 80.2156226, 146.1758883, 24.0653149, 87.81586…
# peru.def.sf
glimpse(peru.def.sf)
#> Rows: 25
#> Columns: 4
#> $ dep       <chr> "AMAZONAS", "ANCASH", "APURIMAC", "AREQUIPA", "AYACUCHO", "C…
#> $ geometry  <GEOMETRY [Β°]> POLYGON ((-77.77036 -5.7881..., POLYGON ((-77.32594…
#> $ Adef_2018 <dbl> 314.4862620, 1.6449195, 3.8862691, 0.0656197, 91.9034760, 65…
#> $ Adef_2019 <dbl> 216.8205146, 0.9261531, 2.2656311, 0.0198774, 65.4541265, 45…

🟣 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