-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathForestCoverageVSAgricultureCoverage.Rmd
282 lines (209 loc) · 10.7 KB
/
ForestCoverageVSAgricultureCoverage.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
---
title: "Forest Coverage vs Agriculture Coverage"
author: "pdelboca"
date: "30/01/2015"
output: html_document
---
## Introduction
In my [last analysis](https://rpubs.com/pdelboca/forest-coverage) I went through the Forest Coverage in the main Countries of
the world. Now I'm practicing 2 Variables analysis so I will add the Agriculture
Coverage of each country to analyze the relationship between deforestation and
agriculture in each country.
My main concern: **Is the World deforesting in order to have more land for Agriculture?**
```{r,echo=FALSE, message=FALSE}
library(reshape2) # melt function
library(ggplot2)
library(gridExtra)
library(dplyr) # arrange
setwd("~/Repos//data-analysis-with-r")
```
## Getting and Cleaning Data
Data has been obtained and downloaded from [Gapminder](http://www.gapminder.org/data/).
There are 2 datasets: **Agricultural land (% of land area)** and **Forest coverage (%)**.
**Note:** Since the goal of this course is not Getting and Cleaning data, I've
manually removed years from Agriculture data to make it easier to read and clean.
*This is not a recomended practice*.
```{r,warning=FALSE}
a.coverage <- read.csv("./data//agriculture land.csv",
col.names = c("Country","1990","2000","2005"))
f.coverage <- read.csv("./data//indicator_forest coverage.csv",
col.names = c("Country","1990","2000","2005"))
a.coverage <- melt(a.coverage, id.vars = c("Country"))
names(a.coverage) <- c("Country","Year","Agriculture.Coverage")
f.coverage <- melt(f.coverage, id.vars = c("Country"))
names(f.coverage) <- c("Country","Year","Forest.Coverage")
data <- merge(a.coverage,f.coverage, by=c("Country","Year"))
data$Year <- gsub("X","",data$Year)
data$Year <- as.factor(data$Year)
data$Agriculture.Coverage <- gsub(",",".",data$Agriculture.Coverage)
data$Agriculture.Coverage <- as.numeric(data$Agriculture.Coverage,na.action)
data$Forest.Coverage <- gsub(",",".",data$Forest.Coverage)
data$Forest.Coverage <- as.numeric(data$Forest.Coverage,na.action)
rm(a.coverage,f.coverage)
head(data)
```
Wow! I'm already learning something. I didn't know that [Afghanistan main economy
was Agriculture](http://en.wikipedia.org/wiki/Afghanistan#Economy)
## Data Processing
#### First some basic histograms of the Variables:
```{r}
p1 <- ggplot(data, aes(x=Forest.Coverage)) + geom_histogram(binwidth = 3) +
facet_wrap(~ Year) +
ggtitle("Forest Coverage around the World per Year")
p2 <- ggplot(data, aes(x=Agriculture.Coverage)) + geom_histogram(binwidth = 3) +
facet_wrap(~ Year) +
ggtitle("Agriculture Coverage around the World per Year")
grid.arrange(p1,p2,ncol = 1)
```
It look's like the Agriculture Coverage tends to a normal distribution. It's a
pity I don't have data from the last 10 years!
#### Let's plot a few BoxPlots:
```{r, warning=FALSE}
ggplot(data, aes(x = Year, y = Forest.Coverage, fill = Year)) +
geom_boxplot(alpha = 0.5) +
scale_y_continuous(breaks = seq(0,100,5)) +
coord_cartesian(ylim = c(00,100)) +
ylab("Average Forest Coverage (%)") +
ggtitle("Average Forest Coverage (%) by Year")
ggplot(data, aes(x = Year, y = Agriculture.Coverage, fill = Year)) +
geom_boxplot(alpha = 0.5) +
scale_y_continuous(breaks = seq(0,100,5)) +
coord_cartesian(ylim = c(00,100)) +
ylab("Average Agriculture Coverage (%)") +
ggtitle("Average Agriculture Coverage (%) by Year")
```
Regarding Agriculture seems that 75% of the countries has 20% or more Agriculture
Coverage and the median is almost 40%.
#### Argentina's Agriculture:
```{r}
argentina <- subset(data, Country == "Argentina")
argentina
```
Agriculture Coverage in Argentina has grown almost a 3% Between 1990 and 2005.
```{r, warning=FALSE}
ggplot(argentina) +
geom_line(aes(x=Year,y=Agriculture.Coverage, group = Country), stat= "identity",
size = 1, color = "red") +
geom_boxplot(data = data , aes(x=Year,y=Agriculture.Coverage, fill = Year), alpha = 0.25) +
ggtitle("Agriculture Coverage (%) Changes in Argentina between 1990 and 2005\n
compared with the average of the World") +
ylab("Average Agriculture Coverage (%)")
```
It's not surprising to see Argentina closer to the 75% Quantile than the median,
[Argentina has a long agriculture tradition](http://en.wikipedia.org/wiki/Agriculture_in_Argentina). Also remind that Argentina is the [8th biggest country in the world](http://simple.wikipedia.org/wiki/List_of_countries_by_area) which gives Argentina a lot of square kilometers dedicated
to the agriculture.
#### Agriculture Coverage vs Forest Coverage
Now let's start plotting some scatterplots:
```{r, warning=FALSE}
ggplot(data, aes(x=Forest.Coverage, y=Agriculture.Coverage)) + geom_point()
```
.... Okay.... No idea of how to read this plot. Let's try plotting only 1 Year,
lets say, the last one:
```{r, warning=FALSE}
ggplot(subset(data, Year == 2005),
aes(x=Forest.Coverage, y=Agriculture.Coverage)) +
geom_point() +
ggtitle("Forest Coverage vs Agriculture Coverage (2005)")
```
Still no idea... :_)
But I can see **a few interesting things**:
* There is a Diagonal tendence with negative slope
* It seems to be a Vertical line near the 0% of Forest Coverage
* There are only a few points above the diagonal
Regarding the third point... There shouldn't be points above the main diagonal,
that will mean that Agriculture Coverage + Forest Coverage is bigger than the 100%
of the land. Two options: **bad data** or some countries uses their forest as
agriculture land... Let's dig a little bit.
```{r, warning=FALSE}
ggplot(subset(data, Year == 2005),
aes(x=Forest.Coverage, y=Agriculture.Coverage)) +
geom_point() +
ggtitle("Forest Coverage vs Agriculture Coverage (2005)") +
geom_abline(intercept = 100, slope = -1, linetype = 2, color = "red") +
scale_y_continuous(breaks = seq(0,100,5)) +
scale_x_continuous(breaks = seq(0,100,5))
subset(data, Forest.Coverage + Agriculture.Coverage > 100)
```
#### Correlation
It's logical to say that Forest Coverage and Agriculture Coverage has a negative
correlation, after all, you need to deforest in order to have more land to grow crops.
Let's see if there is a Correlation between the Forest Coverage and Agriculture Coverage
for 2005 (removing outliers):
```{r}
with(subset(data, Year == 2005 & Forest.Coverage + Agriculture.Coverage < 100),
cor.test(Forest.Coverage,Agriculture.Coverage))
ggplot(subset(data, Year == 2005 & Forest.Coverage + Agriculture.Coverage < 100),
aes(x=Forest.Coverage, y=Agriculture.Coverage)) +
geom_point() +
ggtitle("Forest Coverage vs Agriculture Coverage (2005)") +
geom_abline(intercept = 100, slope = -1, linetype = 2, color = "red") +
scale_y_continuous(breaks = seq(0,100,5)) +
scale_x_continuous(breaks = seq(0,100,5)) +
geom_smooth(method = "lm")
```
#### South America Countries
Let's check South America Countries:
```{r}
south.america <- c("Argentina", "Chile", "Uruguay", "Paraguay", "Brazil",
"Peru", "Ecuador", "Bolivia", "Venezuela", "Colombia",
"Suriname", "French Guiana", "Guyana")
with(subset(data, Year == 2005 & Country %in% south.america),
cor.test(Forest.Coverage,Agriculture.Coverage))
ggplot(subset(data, Year == 2005 & Country %in% south.america),
aes(x=Forest.Coverage, y=Agriculture.Coverage)) +
geom_point(aes(color = Country), size = 5, alpha = 1/2) +
ggtitle("Forest Coverage vs Agriculture Coverage (2005)") +
geom_abline(intercept = 100, slope = -1, linetype = 2, color = "red") +
scale_y_continuous(breaks = seq(0,100,5)) +
scale_x_continuous(breaks = seq(0,100,5)) +
geom_smooth(method = "lm")
```
The correlation in South America countries seems to be stronger than the rest of the world.
Does it mean that countries in South America whit less forest has more agriculture lands?
Does it mean that countries in South America deforest in order to have more land for agriculture?
#### Correlation between changes in Forest Coverage and Changes in Agriculture Coverage
The main question here is: **Is there a correlation between the % of Deforestation and the increment in Agriculture Coverage?**
```{r}
Country <- as.character(unique(data$Country))
Forest.Changes <- subset(data, Year == 2005)$Forest.Coverage - subset(data, Year == 1990)$Forest.Coverage
Agriculture.Changes <- subset(data, Year == 2005)$Agriculture.Coverage - subset(data, Year == 1990)$Agriculture.Coverage
countries.Changes <- data.frame(Country, Forest.Changes, Agriculture.Changes)
countries.Changes$Country <- factor(countries.Changes$Country,
levels = countries.Changes$Country)
summary(countries.Changes)
```
It seems that there is a lot of missing data. Regarding Forest.Coverage it is no
surprising to see those values, but Is it possible that a countrie has change its Ariculture
Coverage in -40%?
Let's look at the Worst 5%...
```{r}
subset(countries.Changes,
Agriculture.Changes < quantile(Agriculture.Changes, probs = 0.05, na.rm = TRUE))
```
I can't found anything about drastic changes on those countries so I'm going to treat them as outliers. What about other outliers?
```{r}
subset(countries.Changes,
Agriculture.Changes > quantile(Agriculture.Changes, probs = 0.95, na.rm = TRUE))
```
It seems that Saudi Arabia [had an amazing increase in its agriculture](http://www.saudiembassy.net/about/country-information/agriculture_water/Agricultural_Achievements.aspx) without
even cutting a single tree. Not so sure about other outliers...
#### Forest Changes vs Agriculture Changes
```{r, warning=FALSE}
ggplot(subset(countries.Changes,
Agriculture.Changes > quantile(Agriculture.Changes, probs = 0.05, na.rm = TRUE)),
aes(x=Forest.Changes, y=Agriculture.Changes)) +
geom_point() +
geom_smooth(method = "lm") +
ggtitle("Forest Coverage Changes vs Agriculture Coverage Changes \n between 1990 and 2005")
ggplot(subset(countries.Changes,
Agriculture.Changes > quantile(Agriculture.Changes, probs = 0.05, na.rm = TRUE) &
Country %in% south.america),
aes(x=Forest.Changes, y=Agriculture.Changes)) +
geom_point(aes(color = Country), alpha = 1/2, size = 5) +
geom_smooth(method = "lm") +
ggtitle("Forest Coverage Changes vs Agriculture Coverage Changes \n between 1990 and 2005 \n in South America")
```
So it seems that Latin America has a greater negative correlation in Changes than the
rest of the World. That could imply indeed that Deforestation main cause is Agriculture (rather than increment of population, cities, infraestructure, etc...)
#### Conclusion
Although there seems to be a negative correlation between Forest Coverage and Agriculture Coverage, mostly in South America Countries, I feel I cannot rely in the data due to some strange outliers described above and missing data.