05 March 2015

Exploring the structure of national consumption

This entry is my first exploration of the structure of national resource consumption

library(ggplot2)
# READING IN DATA

## SETTING DIRECTORY FOR EORA DATA ON LOCAL HARD DRIVE
wd<-"G:/Documents/PostDocKVA/Data/Eora" ### data directory
setwd(wd)
dir()
##  [1] "countries.csv"              "country_lookup.csv"        
##  [3] "Eora26_2011_bp.zip"         "Eora26Structure.xlsx"      
##  [5] "gdppop.csv"                 "regionmembership.csv"      
##  [7] "TradeBalance_I-ENERGY.csv"  "TradeBalance_I-ENERGY.xlsx"
##  [9] "TradeBalance_I-VA.csv"      "TradeBalance_I-VA.xlsx"    
## [11] "Wiedmann"
## READING IN MATERIAL USE DATA - ENERGY DATASET
energy.df<-read.csv("TradeBalance_I-ENERGY.csv",header=TRUE)
head(energy.df)
##       Country CountryA3    y TerritorialEmissions Imports Exports
## 1 Afghanistan       AFG 2011                 2120   47872      32
## 2     Albania       ALB 2011                76785   38725    8777
## 3     Algeria       DZA 2011              1595798  275304  791087
## 4     Andorra       AND 2011                    0    8185       0
## 5      Angola       AGO 2011               568776  174772  120704
## 6     Antigua       ATG 2011                    0    7192       0
##   DirectEmissions Consumption
## 1             949       49959
## 2           11011      106734
## 3          251668     1080016
## 4               0        8185
## 5          255897      622844
## 6               0        7192
ggplot(energy.df,aes(y=Consumption,x=y)) + geom_point()

Some of the entries are negative. Let’s remove those.

energy.df<-energy.df[which(energy.df[,"Consumption"]>0),]
ggplot(energy.df,aes(y=Consumption,x=y,group=CountryA3)) + geom_line()

What are the units we are looking at?

unique(sort(energy.df$Country))
##   [1] Afghanistan              Albania                 
##   [3] Algeria                  Andorra                 
##   [5] Angola                   Antigua                 
##   [7] Argentina                Armenia                 
##   [9] Aruba                    Australia               
##  [11] Austria                  Azerbaijan              
##  [13] Bahamas                  Bahrain                 
##  [15] Bangladesh               Barbados                
##  [17] Belarus                  Belgium                 
##  [19] Belize                   Benin                   
##  [21] Bermuda                  Bhutan                  
##  [23] Bolivia                  Bosnia and Herzegovina  
##  [25] Botswana                 Brazil                  
##  [27] British Virgin Islands   Brunei                  
##  [29] Bulgaria                 Burkina Faso            
##  [31] Burundi                  Cambodia                
##  [33] Cameroon                 Canada                  
##  [35] Cape Verde               Cayman Islands          
##  [37] Central African Republic Chad                    
##  [39] Chile                    China                   
##  [41] Colombia                 Congo                   
##  [43] Costa Rica               Cote dIvoire            
##  [45] Croatia                  Cuba                    
##  [47] Cyprus                   Czech Republic          
##  [49] Denmark                  Djibouti                
##  [51] Dominican Republic       DR Congo                
##  [53] Ecuador                  Egypt                   
##  [55] El Salvador              Eritrea                 
##  [57] Estonia                  Ethiopia                
##  [59] Fiji                     Finland                 
##  [61] Former USSR              France                  
##  [63] French Polynesia         Gabon                   
##  [65] Gambia                   Gaza Strip              
##  [67] Georgia                  Germany                 
##  [69] Ghana                    Greece                  
##  [71] Greenland                Guatemala               
##  [73] Guinea                   Guyana                  
##  [75] Haiti                    Honduras                
##  [77] Hong Kong                Hungary                 
##  [79] Iceland                  India                   
##  [81] Indonesia                Iran                    
##  [83] Iraq                     Ireland                 
##  [85] Israel                   Italy                   
##  [87] Jamaica                  Japan                   
##  [89] Jordan                   Kazakhstan              
##  [91] Kenya                    Kuwait                  
##  [93] Kyrgyzstan               Laos                    
##  [95] Latvia                   Lebanon                 
##  [97] Lesotho                  Liberia                 
##  [99] Libya                    Liechtenstein           
## [101] Lithuania                Luxembourg              
## [103] Macao SAR                Madagascar              
## [105] Malawi                   Malaysia                
## [107] Maldives                 Mali                    
## [109] Malta                    Mauritania              
## [111] Mauritius                Mexico                  
## [113] Moldova                  Monaco                  
## [115] Mongolia                 Montenegro              
## [117] Morocco                  Mozambique              
## [119] Myanmar                  Namibia                 
## [121] Nepal                    Netherlands             
## [123] Netherlands Antilles     New Caledonia           
## [125] New Zealand              Nicaragua               
## [127] Niger                    Nigeria                 
## [129] North Korea              Norway                  
## [131] Oman                     Pakistan                
## [133] Panama                   Papua New Guinea        
## [135] Paraguay                 Peru                    
## [137] Philippines              Poland                  
## [139] Portugal                 Qatar                   
## [141] Romania                  Russia                  
## [143] Rwanda                   Samoa                   
## [145] San Marino               Sao Tome and Principe   
## [147] Saudi Arabia             Senegal                 
## [149] Serbia                   Seychelles              
## [151] Sierra Leone             Singapore               
## [153] Slovakia                 Slovenia                
## [155] Somalia                  South Africa            
## [157] South Korea              South Sudan             
## [159] Spain                    Sri Lanka               
## [161] Sudan                    Suriname                
## [163] Swaziland                Sweden                  
## [165] Switzerland              Syria                   
## [167] Taiwan                   Tajikistan              
## [169] Tanzania                 TFYR Macedonia          
## [171] Thailand                 Togo                    
## [173] Trinidad and Tobago      Tunisia                 
## [175] Turkey                   Turkmenistan            
## [177] UAE                      Uganda                  
## [179] UK                       Ukraine                 
## [181] Uruguay                  USA                     
## [183] Uzbekistan               Vanuatu                 
## [185] Venezuela                Viet Nam                
## [187] Yemen                    Zambia                  
## [189] Zimbabwe                
## 190 Levels: Afghanistan Albania Algeria Andorra Angola ... Zimbabwe

We see 190 national units in the dataset - including the “Former USSR”.

Let’s first highlight and then remove that entry.

ggplot(energy.df[which(as.character(energy.df$Country)=="Former USSR"),],aes(y=Consumption,x=y)) + geom_line()

## REMOVING FORMER USSR
energy.df<-energy.df[-which(as.character(energy.df$Country)=="Former USSR"),]

To make consumption more comparable let’s calculate per capita consumption by associating population data

#Reading in .csv file with annual gdp and population sizes
setwd(wd)

gdppop.df<-read.csv("gdppop.csv",header=TRUE,skip=1) #skipping the first line which includes a description of the file

## taking a look at the gdp and population file
head(gdppop.df)
##   Country CountryA3    y      GDP   val
## 1   Aruba       ABW 1970 201904.2 56771
## 2   Aruba       ABW 1971 213043.3 57253
## 3   Aruba       ABW 1972 224756.6 57730
## 4   Aruba       ABW 1973 235870.2 58189
## 5   Aruba       ABW 1974 244441.6 58610
## 6   Aruba       ABW 1975 255802.9 58983
## merging the gdp and population size data onto the energy consumption data frame
energy.df<-merge(energy.df,gdppop.df,by=c("CountryA3","y"),all.x=TRUE)

ggplot(energy.df,aes(y=Consumption/val,x=y,group=CountryA3)) + geom_line()
## Warning: Removed 320 rows containing missing values (geom_path).

ggplot(energy.df,aes(y=Consumption/GDP,x=y,group=CountryA3)) + geom_line()



blog comments powered by Disqus