R Markdown Presentation & Plotly

Brazilian Amazon Forest deforestation

Danilo Correa

October 1, 2019

Brazilian Amazon Forest deforestation

According to the Brazilian National Space Research Institute - INPE, the annual rate consolidated by the Satellite Legal Amazon Deforestation Monitoring Project (PRODES) showed the result of 7,536 kmĀ² of shallow cut from August 2017 to July 2018, an area equivalent to Trinidad and Tobago territory.

The PRODES project performs satellite monitoring of clearcut deforestation in the Legal Amazon and since 1988 has produced annual deforestation rates in the region, which are used by the Brazilian government to establish public policies. Annual rates are estimated from the deforestation increments identified in each satellite image covering the Legal Amazon. The first presentation of the data is made for December of each year as an estimate. Consolidated data are presented in the first half of the following year.

Main Brazilian Amazon Forest Protected Areas

How is the current degree of deforestation in federal protected areas?

To address this question, I performed the following analysis steps:

  1. Download the Deforestation in Protected Areas data from PRODES;
  2. Calculate the annual deforestation increment in the Brazilian Amazon Forest;
  3. Make a plot with the results.

Loading required packages:

knitr::opts_chunk$set()
if (!"data.table" %in% rownames(installed.packages())) {install.packages("data.table")}
library(data.table)

if (!"plotly" %in% rownames(installed.packages())) {install.packages("plotly")}
library(plotly)

if (!"spData" %in% rownames(installed.packages())) {install.packages("spData")}
library(spData)

Data preparation:

# Directly download and read the dataset:
prodes <- fread("http://www.dpi.inpe.br/prodesdigital/tabelatxt_uc.php?ano=2018&estado=&esfera=Federal&grupo=&categoria=&ordem=DESMATAMENTO_1997&type=tabela&output=txt&")

# sum total deforestation per year:
anual <- lapply(prodes[,20:39], function(x) sum(as.numeric(as.character(x)), na.rm = TRUE))

# create a data.frame:
dt <- as.data.frame(do.call(rbind, anual))

# calculate the annual deforestation increment:
dt$cumulative_logging <- cumsum(apply(dt,1,sum))

# assign column names:
colnames(dt) <- c("logging", "cumulative_logging")

# assign "years":
year <- 2000:2018
year <- c(1997, year)
dt$year <- year

# reorder columns:
dt <- dt[c(3,1,2)]

# extract years from 2000 until 2018:
dt <- dt[2:20,]

# create a world data.frame (from spData package)
world <- world

# reorder world by country area:
world <- world[order(world$area_km2),]

# find countries with equivalent areas to annual deforestation areas:
countries <- world$name_long[findInterval(dt$cumulative_logging, vec = world$area_km2)]

# get unique results:
unique(countries)

# create unique.countries vector:
unique.countries <- c("Northern Cyprus","Palestine","","Cyprus","",
                      "Trinidad and Tobago","","","","","Puerto Rico","","","",
                      "","","Lebanon","","Brunei Darussalam")

Making a plotly plot:

p <- plot_ly(data = dt, 
             x = dt$year, 
             y = dt$cumulative_logging, 
             type = "bar",
             marker = list(color = colorRampPalette(list('yellow', 'red'))(19))) %>%
    add_annotations(x = dt$year,
                    y = dt$cumulative_logging,
                    text = unique.countries,
                    xref = "x",
                    yref = "y",
                    showarrow = FALSE,
                    arrowhead = 4,
                    arrowsize = .5,
                    ax = 20,
                    ay = -40,
                    yanchor = 'bottom') %>%
    layout(title = list(text = paste0('<b>Brazilian Amazon logging in Federal Protected Areas since 2000</b>',
                                      '<br>',
                                      '<sup>',
                                      '(with country equivalent areas)',
                                      '</sup>')),
           xaxis = list(title = "Year"),
           yaxis = list(title = "Deforested Area (Km<sup>2</sup>)"),
           images = list(
               source = "https://image.flaticon.com/icons/svg/1552/1552679.svg",
               xref = "paper",
               yref = "paper",
               x= 0,
               y= 1,
               sizex = 0.2,
               sizey = 0.2,
               opacity = 0.8)) %>% 
            add_annotations(
                 xref="paper",
                 yref="paper",
                 x= 1,
                 y= -0.07,
                 text = paste("Data source: ","<a href='http://www.dpi.inpe.br/prodesdigital/prodesuc.php'>INPE</a>"),
                 showarrow = F
                 )

Plotly plot result: