Introduction

Introduction

This dashboard explores how climate change has affected the world, the African continent and Ethiopia. Ethiopia is a country located on the horn of east Africa.

Throughout this dashboard, there will be some interesting graphical representations which include but are not limited to the following:

  • According to the data, has there been a constant increase to the world’s temperature?
  • According to the data, which year was the hottest overall in the world?
  • Compare the temperature change of the African Continent in 2019 and 2021.
  • As of 2021, which African country has had that highest mean temperature change?
  • As of 2021, which African country has had that lowest mean temperature change?
  • Has climate change affected Ethiopia’s temperature throughout time?

The Data originally included 2535 observations of 14 variables. Some of these variables were not necessary therefore I filtered in 6 of the 14. The data is as follows:

  • Area: This is the African countries name and the world collectively.
  • Element: “Temperature change”, “Standard Deviation”
  • Year: the years between 1978 - 2021
  • Unit: “Degree C”
  • Value: The mean temperature change

Climate Change

Column {data-width=650}

World

Africa

row

Footnote

The figures above illustrate the mean temperature change. The first figure focuses on the change in the world from 1978 - 2021. As shown above, there is a positive skewed bar chart that indicates that the worlds climate has been increasing significantly throughout the years. Furthermore, when looking at the graph, we can see that 2020 had the highest mean temperature change of 1.713 degrees. The second figure focuses on the change in temperature within the African continent in 2021. According to the diagram, Zimbabwe has the lowest temperature change of -0.101, while Tunisia has the highest change of 2.543 degrees in 2021.

Africa

Column

African Map 2019

African Map 2021

Column

Africa Comparison by Region

Ethiopia

Column

Ethiopian Climate Change

row

Footnote

The figures above illustrate the mean temperature change within Ethiopia from the year 1993 - 2021. As shown above, there is a clear positive trend line on the scatter plot that indicated that Ethiopia’s climate has been increasing throughout the years.

The reason this graph is from 1993 and not 1978 like our previous data is because there is no temperature data recorded for Ethiopia prior to 1993 in the data set being used.

Data Citation

Citation The data is from:

“FAO.[FAOSTAT_data_en_2-14-2023]. License: CC BY-NC-SA 3.0 IGO. Extracted from: [https://www.fao.org/faostat/en/#data/ET]. Data of Access: [02-14-2023].”

---
title: "Climate Change Analysis"
author: "Belosan W Jekale"
date: "2023-02-16"
output: 
  flexdashboard::flex_dashboard:
    orientation: rows
    vertical_layout: fill
    source_code: embed
---

```{r packages, echo=FALSE}
#install.packages("flexdashboard", type = "source") used
library(flexdashboard)
library(dplyr)
#install.packages("quantmod")
library(quantmod)
library(plyr)
#install.packages("xts") 
library(xts)
#install.packages("dygraphs")
library(dygraphs)
#install.packages("DT")
library(DT)
#install.packages("ggplot2") 
library(ggplot2)
#install.packages("plotly") 
library(plotly)
#install.packages("ggmap")
library(ggmap)
#install.packages("maps")
library(maps)
#install.packages("mapdata")
library(mapdata)
#install.packages("mapproj")
library(mapproj)
```

```{r setup, include=FALSE}
climateData <- read.csv("C:/Users/billy/OneDrive/Documents/ANLY 512/FAOSTAT_data_en_2-14-2023 (temp change).csv")

climateData <- climateData %>%
  select(c("Area", "Element", "Year", "Unit", "Value"))

climateData$Area <- factor(climateData$Area)
climateData$Element <- factor(climateData$Element)
climateData$Unit <- factor(climateData$Unit)

climateData <- na.omit(climateData)
str(climateData)
summary(climateData)
```

# Introduction 
### Introduction 

This dashboard explores how climate change has affected the world, the African continent and Ethiopia. Ethiopia is a country located on the horn of east Africa.

Throughout this dashboard, there will be some interesting graphical representations which include but are not limited to the following:

  * According to the data, has there been a constant increase to the world's temperature?
  * According to the data, which year was the hottest overall in the world?
  * Compare the temperature change of the African Continent in 2019 and 2021.
  * As of 2021, which African country has had that highest mean temperature change?
  * As of 2021, which African country has had that lowest mean temperature change?
  * Has climate change affected Ethiopia's temperature throughout time?
  
  
The Data originally included 2535 observations of 14 variables. Some of these variables were not necessary therefore I filtered in 6 of the 14. The data is as follows:

  * **Area**: This is the African countries name and the world collectively.
  * **Element**: "Temperature change", "Standard Deviation"
  * **Year**: the years between 1978 - 2021
  * **Unit**: "Degree C"
  * **Value**: The mean temperature change
  

# Climate Change 

Column {data-width=650} {.tabset .tabset-fade} 
-----------------------------------------------------------------------

### World 

```{r}
worldData <- climateData %>%
  select(Area, Element, Year, Unit, Value) %>%
  filter(Area == "World") 

world <- ggplot(worldData, aes(x = Year, y = Value)) +
        geom_bar(stat="identity", fill="lightblue") +
        theme_classic() +
        theme(legend.position="none") +
        labs(x = "Year", 
             y = "Mean Temperature Change (C)",
             title = "World Mean Temperature Change (1978 - 2021)") 

ggplotly(world)
```

### Africa  

```{r}
africaData <- climateData %>%
  select(Area, Element, Year, Unit, Value) %>%
  filter(!Area %in%  c("World", "Eastern Africa", "Middle Africa", "Northern Africa", "Southern Africa", "Western Africa"), Element == "Temperature change", Year == 2021)
  
africa <- ggplot(africaData, aes(x = Value, y = Area, text = Area)) +
            geom_bar(stat="identity", fill="lightblue") +
            theme_classic() +
            theme(legend.position="none") +
            labs(x = "Mean Temperature Change (C)", 
                 y = "African Countries",
                 title = "African Countries Mean Temperature Change (2021)") 

ggplotly(africa)

```


## row {data-height=60}
### Footnote 

The figures above illustrate the mean temperature change. 
The first figure focuses on the change in the world from 1978 - 2021. As shown above, there is a positive skewed bar chart that indicates that the worlds climate has been increasing significantly throughout the years. Furthermore, when looking at the graph, we can see that 2020 had the highest mean temperature change of 1.713 degrees. The second figure focuses on the change in temperature within the African continent in 2021. According to the diagram, Zimbabwe has the lowest temperature change of -0.101, while Tunisia has the highest change of 2.543 degrees in 2021.

# Africa 

## Column{.sidebar}
To the right, is a comparison of the mean temperature change in degrees Celsius of the African Continent between 2019 and 2021. A color gradient that ranges from white to dark red portrays the temperature change value white being a small temperature of less than or equal to 0 degrees and as the mean temperature increases the color moves towards dark red. As shown in the two African maps, 2019 has a more of a lighter pink color throughout and 2021 has a darker color when compared to 2019. Concluding that climate change has indeed affected the African continent as a whole.

Further more, the line plot to the right portrays the Africa divided into the following regions:

* Eastern Africa
* Middle Africa
* Northern Africa
* Southern Africa
* Western Africa 

Here we can see the trend lines of each region's mean temperature change from 1978 to 2021. The graph is also interactive, therefore, by clicking the regions in the legend on the top right of the graph, the viewer is able to isolate a region trend line and add whichever region line they choose. 

**Click a region on the legend to test**



Column {data-width=350}
-----------------------------------------------------------------------

### African Map 2019

```{r}
africaData2019 <- climateData %>%
  select(Area, Element, Year, Unit, Value) %>%
  filter( !Area %in% c("World", "Eastern Africa", "Middle Africa", "Northern Africa", "Southern Africa", "Western Africa"), Element == "Temperature change", Year == 2019)

world <- map_data("world")
africa <- subset(world, region %in% c("Algeria","Angola","Benin","Botswana","Burkina Faso","Burundi",
                                      "Cabo Verde","Cameroon","Central African Republic","Chad","Comoros",
                                      "Democratic Republic of the Congo","Republic of Congo","Ivory Coast",
                                      "Djibouti","Egypt","Equatorial Guinea","Eritrea","Swaziland","Ethiopia",
                                      "Gabon","Gambia","Ghana","Guinea","Guinea-Bissau","Kenya","Lesotho","Liberia",
                                      "Libya","Madagascar","Malawi","Mali","Mauritania","Mauritius","Morocco",
                                      "Mozambique","Namibia","Niger","Nigeria","Rwanda","Sao Tome and Principe",
                                      "Senegal","Seychelles","Sierra Leone","Somalia","South Africa","South Sudan",
                                      "Sudan","Tanzania","Togo","Tunisia","Uganda","Zambia","Zimbabwe"))
names(africaData2019)[1] <- "region"
africaMergedData <- merge(africa,africaData2019,by="region")

ggplot() +
  geom_polygon(data=africaMergedData,aes(x=long, y=lat, group = group, fill=Value),color="grey")+
  coord_map()+ 
  labs(title = "African Mean Temperature Change by Countries (2019)") +
  scale_fill_gradient(name="Temperature (C)",low="whitesmoke",high="darkred")+
  theme_void()

```


### African Map 2021

```{r}
world <- map_data("world")
africa1 <- subset(world, region %in% c("Algeria","Angola","Benin","Botswana","Burkina Faso","Burundi",
                                      "Cabo Verde","Cameroon","Central African Republic","Chad","Comoros",
                                      "Democratic Republic of the Congo","Republic of Congo","Ivory Coast",
                                      "Djibouti","Egypt","Equatorial Guinea","Eritrea","Swaziland","Ethiopia",
                                      "Gabon","Gambia","Ghana","Guinea","Guinea-Bissau","Kenya","Lesotho","Liberia",
                                      "Libya","Madagascar","Malawi","Mali","Mauritania","Mauritius","Morocco",
                                      "Mozambique","Namibia","Niger","Nigeria","Rwanda","Sao Tome and Principe",
                                      "Senegal","Seychelles","Sierra Leone","Somalia","South Africa","South Sudan",
                                      "Sudan","Tanzania","Togo","Tunisia","Uganda","Zambia","Zimbabwe"))
names(africaData)[1] <- "region"
africaMergedData1 <- merge(africa1,africaData,by="region")

ggplot() +
  geom_polygon(data=africaMergedData1,aes(x=long, y=lat, group = group, fill=Value),color="grey")+
  coord_map()+ 
  labs(title = "African Mean Temperature Change by Countries (2021)") +
  scale_fill_gradient(name="Temperature (C)",low="whitesmoke",high="darkred")+
  theme_void()

```

Column {data-width=650}
-----------------------------------------------------------------------

### Africa Comparison by Region

```{r}
regionalData <- climateData %>%
  select(Area, Element, Year, Unit, Value) %>%
  filter(Area %in% c("Eastern Africa", "Middle Africa", "Northern Africa", "Southern Africa", "Western Africa"), Element == "Temperature change")

africanRegions <- ggplot(regionalData, aes(x = Year, y = Value, group = Area)) +
            geom_line(aes(color = Area))+
            geom_point(aes(color = Area))+
            theme_classic() +
            labs(x = "Year", 
                 y = "Mean Temperature Change (C)",
                 title = "African Mean Temperature Change by Region", 
                 color = "African Regions") +
            scale_color_brewer(palette="Dark2") +
            theme(legend.position = "right")

ggplotly(africanRegions)
```


# Ethiopia

Column {data-width=350}
-----------------------------------------------------------------------

### Ethiopian Climate Change

```{r}
ethioData <- climateData %>%
  select(Area, Element, Year, Unit, Value) %>%
  filter(Area == "Ethiopia")
  
ethio <- ggplot(ethioData, aes(x = Year, y = Value)) +
            geom_point(stat="identity") +
            geom_smooth(method=lm) +
            theme_classic() +
            theme(legend.position="none") +
            labs(x = "Year", 
                 y = "Mean Temperature Change (C)",
                 title = "Ethiopian Mean Temperature Change (1993 - 2021)") 

ggplotly(ethio)

```

## row {data-height=80}
### Footnote 

The figures above illustrate the mean temperature change within Ethiopia from the year 1993 - 2021. As shown above, there is a clear positive trend line on the scatter plot that indicated that Ethiopia's climate has been increasing throughout the years.

The reason this graph is from 1993 and not 1978 like our previous data is because there is no temperature data recorded for Ethiopia prior to 1993 in the data set being used. 


# Data Citation

**Citation**
The data is from:

“FAO.[FAOSTAT_data_en_2-14-2023]. License: CC BY-NC-SA 3.0 IGO. Extracted from: [https://www.fao.org/faostat/en/#data/ET]. Data of Access: [02-14-2023].”