forestpop

Analuses for Dylan Phillot

Here we start by wrangling the date to find the best table to analyse

PopForestData <- read.csv("~/Downloads/PopForestData.csv", dec=",", sep=",")
library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.4     ✔ readr     2.1.5
✔ forcats   1.0.0     ✔ stringr   1.5.1
✔ ggplot2   3.5.1     ✔ tibble    3.2.1
✔ lubridate 1.9.3     ✔ tidyr     1.3.1
✔ purrr     1.0.2     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
glimpse(PopForestData)
Rows: 11,964
Columns: 53
$ feature_id           <int> 59460, 59460, 59460, 59460, 59460, 59460, 59460, …
$ biome                <chr> "Caatinga", "Caatinga", "Caatinga", "Caatinga", "…
$ municipality         <chr> "Acauã", "Acauã", "Acauã", "Acauã", "Acauã", "Aca…
$ state_acronym        <chr> "PI", "PI", "PI", "PI", "PI", "PI", "PI", "PI", "…
$ municipality_state   <chr> "Acauã - PI", "Acauã - PI", "Acauã - PI", "Acauã …
$ geocode              <int> 2200053, 2200053, 2200053, 2200053, 2200053, 2200…
$ biome..municipality. <chr> "Caatinga [Acauã]", "Caatinga [Acauã]", "Caatinga…
$ class_id             <int> 3, 4, 12, 29, 15, 41, 21, 24, 25, 33, 3, 4, 12, 2…
$ level_0              <chr> "Natural", "Natural", "Natural", "Natural", "Anth…
$ level_1              <chr> "1. Forest", "1. Forest", "2. Non Forest Natural …
$ level_2              <chr> "Forest Formation", "Savanna Formation", "Grassla…
$ level_3              <chr> "Forest Formation", "Savanna Formation", "Grassla…
$ level_4              <chr> "Forest Formation", "Savanna Formation", "Grassla…
$ color                <chr> "#006400", "#00ff00", "#b8af4f", "#665a3a", "#ffd…
$ category             <chr> "refined_biome_per_city", "refined_biome_per_city…
$ X1985                <dbl> NA, 84645.536016, 10145.660507, 64.760207, 9272.9…
$ X1986                <dbl> NA, 84613.234117, 9569.788005, 68.741563, 9265.49…
$ X1987                <dbl> NA, 85987.701070, 8654.575591, 67.149264, 10343.7…
$ X1988                <dbl> NA, 83400.627445, 11053.629833, 68.741859, 12746.…
$ X1989                <dbl> NA, 8.100819e+04, 1.299184e+04, 6.980335e+01, 1.5…
$ X1990                <dbl> NA, 7.862900e+04, 1.245553e+04, 6.706059e+01, 1.8…
$ X1991                <dbl> NA, 7.822720e+04, 1.121065e+04, 6.776852e+01, 2.0…
$ X1992                <dbl> NA, 7.344697e+04, 1.421583e+04, 6.953800e+01, 2.0…
$ X1993                <dbl> NA, 7.179645e+04, 1.444114e+04, 6.759155e+01, 2.2…
$ X1994                <dbl> NA, 74001.595697, 10597.533960, 67.237607, 21111.…
$ X1995                <dbl> 4.423270e-01, 7.446701e+04, 8.074734e+03, 7.07766…
$ X1996                <dbl> 4.423270e-01, 7.587898e+04, 5.917917e+03, 7.44039…
$ X1997                <dbl> 2.034826e+00, 8.097075e+04, 3.006099e+03, 7.84737…
$ X1998                <dbl> 2.123301e+00, 7.957640e+04, 2.529194e+03, 7.89160…
$ X1999                <dbl> 1.504034e+00, 7.816308e+04, 2.950581e+03, 7.98009…
$ X2000                <dbl> 7.962734e-01, 7.678070e+04, 2.616557e+03, 7.81200…
$ X2001                <dbl> 7.962734e-01, 7.489164e+04, 4.650588e+03, 7.73237…
$ X2002                <dbl> 1.061698, 68854.252250, 14799.380080, 80.154726, …
$ X2003                <dbl> 1.061698e+00, 6.469454e+04, 1.856892e+04, 8.01547…
$ X2004                <dbl> 8.847480e-01, 6.296745e+04, 1.899258e+04, 7.99777…
$ X2005                <dbl> 8.847480e-01, 6.129921e+04, 1.985634e+04, 7.84738…
$ X2006                <dbl> 4.423740e-01, 6.071912e+04, 1.848114e+04, 7.76777…
$ X2007                <dbl> NA, 62222.248776, 10432.376931, 75.731310, 44213.…
$ X2008                <dbl> NA, 61867.587435, 10466.240896, 74.138812, 45707.…
$ X2009                <dbl> NA, 6.181135e+04, 1.078542e+04, 7.192708e+01, 4.4…
$ X2010                <dbl> NA, 6.206925e+04, 1.061573e+04, 7.086549e+01, 4.1…
$ X2011                <dbl> NA, 61410.433433, 13734.328784, 70.777010, 41895.…
$ X2012                <dbl> 2.831007, 58545.768595, 17797.394500, 73.077154, …
$ X2013                <dbl> 4.777273e+00, 5.398495e+04, 2.212979e+04, 7.36965…
$ X2014                <dbl> 5.838837, 52979.491434, 21959.194062, 77.854698, …
$ X2015                <dbl> 1.088179e+01, 5.045148e+04, 2.169691e+04, 8.05970…
$ X2016                <dbl> 11.678028, 50081.904235, 21649.883788, 80.420002,…
$ X2017                <dbl> 16.897719, 49946.209446, 21047.733840, 79.358368,…
$ X2018                <dbl> 14.597636, 48231.759509, 22170.679690, 82.720232,…
$ X2019                <dbl> 13.182075, 48331.174014, 24299.199709, 82.897183,…
$ X2020                <dbl> 13.182075, 48282.766899, 24472.703786, 81.924044,…
$ X2021                <dbl> 13.093607, 48152.599123, 24700.546509, 81.481717,…
$ X2022                <dbl> 13.093607, 48139.302429, 24686.284225, 81.393429,…
PopForestData %>% 
  filter(biome=="Caatinga" & level_0=="Natural"& level_1 !="5. Water" & level_1 !="6. Non Observed") %>% # exclude levels of variable of no itnerest
  group_by(municipality,state_acronym,geocode) %>% # grouping by municipalities
  summarise(across(X1985:X2022, sum, na.rm=TRUE)) %>%  #%>% # then summing across all natural vegetation types per year and remove NAs to avoid affecting the sum
  mutate(def_rate= (X1985-X2022)/38) %>% # land use change rate in 38 years considering all bvegetation types
  mutate(accum_def=X1985-X2022) %>% # accumulated loss of vegetation across the whole period
  select(municipality, X1985,X2022, accum_def,def_rate) %>% # checking the data
  arrange(desc(accum_def))  # ordered by accumulated deforestation
`summarise()` has grouped output by 'municipality', 'state_acronym'. You can
override using the `.groups` argument.
Adding missing grouping variables: `state_acronym`
# A tibble: 1,209 × 6
# Groups:   municipality, state_acronym [1,209]
   state_acronym municipality         X1985   X2022 accum_def def_rate
   <chr>         <chr>                <dbl>   <dbl>     <dbl>    <dbl>
 1 BA            Sento Sé           956293. 849072.   107221.    2822.
 2 BA            Xique-Xique        394616. 297677.    96939.    2551.
 3 BA            Pilão Arcado      1004572. 908993.    95579.    2515.
 4 BA            Bom Jesus da Lapa  282274. 197385.    84890.    2234.
 5 BA            Campo Formoso      566583. 482113.    84471.    2223.
 6 PE            Petrolina          370960. 287007.    83952.    2209.
 7 BA            Macururé           155216.  80108.    75108.    1977.
 8 BA            Itaguaçu da Bahia  333018. 265659.    67359.    1773.
 9 BA            Serra do Ramalho   156575.  98420.    58155.    1530.
10 MG            Jaíba              132852.  75071.    57780.    1521.
# ℹ 1,199 more rows

Nowe we need to find the data with the area of municipality so we can use it to calculate percentages