This is a warm-up exercise for using R Markdown in making reports. To this end we have used a Gapminder Dataset.
The following part, loads the data from the input URL.
gdURL <- "http://www.stat.ubc.ca/~jenny/notOcto/STAT545A/examples/gapminder/data/gapminderDataFiveYear.txt"
gDat <- read.delim(file = gdURL)
The number of observation is obtained by counting the total number of rows in the data.
nrow(gDat)
## [1] 1704
There are several variables, in the data set,describing these observations
colnames(gDat)
## [1] "country" "year" "pop" "continent" "lifeExp" "gdpPercap"
Some very basic descriptive statistics for the data is obtained as follows
summary(gDat)
## country year pop continent
## Afghanistan: 12 Min. :1952 Min. :6.00e+04 Africa :624
## Albania : 12 1st Qu.:1966 1st Qu.:2.79e+06 Americas:300
## Algeria : 12 Median :1980 Median :7.02e+06 Asia :396
## Angola : 12 Mean :1980 Mean :2.96e+07 Europe :360
## Argentina : 12 3rd Qu.:1993 3rd Qu.:1.96e+07 Oceania : 24
## Australia : 12 Max. :2007 Max. :1.32e+09
## (Other) :1632
## lifeExp gdpPercap
## Min. :23.6 Min. : 241
## 1st Qu.:48.2 1st Qu.: 1202
## Median :60.7 Median : 3532
## Mean :59.5 Mean : 7215
## 3rd Qu.:70.8 3rd Qu.: 9325
## Max. :82.6 Max. :113523
##
In this part we see the trend in per capita GDP for two neighboring countries : Iran and Iraq from 1952 to 2007:
library(lattice)
xyplot(gdpPercap ~ year, gDat, subset = (country == "Iraq" | country == "Iran"),
group = country, type = c("p", "spline"), key = list(lines = Rows(trellis.par.get("superpose.line"),
c(5:6)), text = list(lab = c("Iran", "Iraq")), columns = 2, title = "Per Capita GDP in two neighboring countries"))
As we see, a big decline in Per Capita GDP for Iran occured close to First Persian Gulf (Iran-Iraq) War (1980-1988). Afterwards, Iran has started to grow in Per Capita GDP, however Iraq continues the decline during and even after the second Persian Gulf war (1990-1991). Iraq's second decline in GDP per capita started during the next war (2003).