-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathblock10_customPanelProcess.R
33 lines (27 loc) · 1.41 KB
/
block10_customPanelProcess.R
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
gdURL <- "http://www.stat.ubc.ca/~jenny/notOcto/STAT545A/examples/gapminder/data/gapminderDataFiveYear.txt"
gDat <- read.delim(file = gdURL)
str(gDat)
gdURL <- "http://www.stat.ubc.ca/~jenny/notOcto/STAT545A/examples/gapminder/data/gapminderContinentColors.txt"
continentColors <- read.delim(file = gdURL, as.is = 3) # protect color
continentColors
## continent nCountries color
## 1 Africa 52 #7F3B08
## 2 Americas 25 #A50026
## 3 Asia 33 #40004B
## 4 Europe 30 #276419
## 5 Oceania 2 #313695
gdURL <- "http://www.stat.ubc.ca/~jenny/notOcto/STAT545A/examples/gapminder/data/gapminderCountryColors.txt"
countryColors <- read.delim(file = gdURL, as.is = 3) # protect color
str(countryColors)
## 'data.frame': 142 obs. of 3 variables:
## $ continent: Factor w/ 5 levels "Africa","Americas",..: 1 1 1 1 1 1 1 1 1 1 ...
## $ country : Factor w/ 142 levels "Afghanistan",..: 95 39 43 28 118 121 127 6..
## $ color : chr "#7F3B08" "#833D07" "#873F07" "#8B4107" ...
## insert color as a variable in gDat
gDat <- merge(gDat, countryColors)
## Sort by year (increasing) and population (decreasing)
## Why? So larger countries will be plotted "under" smaller ones.
gDatOrdered <- with(gDat, gDat[order(year, -1 * pop),])
## we are ready to start plotting
write.table(gDatOrdered, "gapminderWithColorsAndSorted.txt", quote = FALSE,
sep = "\t", row.names = FALSE)