R

FAO item codes, oh my.

I was just having a look at the FAOSTAT package as I wanted an example of pulling data in from public sources off the internet.

library("FAOSTAT")
library("countrycode")
headmilkcows <- getFAO(name = "headofcows", domainCode = "QL", elementCode = 5318, itemCode = 882)
arableland <- getFAOtoSYB("land", domainCode = "RL", elementCode = 5110, itemCode = 6621)[[1]]
combined <- merge(headmilkcows, arableland)
combined$Country <- countrycode(combined$FAOST_CODE, "fao", "country.name")
criteria <- combined$Year == 2013
plot(log(combined$land[criteria]), log(combined$headofcows[criteria]), main="2013 Arable land and Head of milk cows by county", xlab="Arable Land Area (log scale)", ylab="Head of Milk Cows (log scale)", col="grey40")
criteria <- combined$Year == 2013 & combined$Country == "New Zealand"
points(log(combined$land[criteria]), log(combined$headofcows[criteria]), pch=19, col="black")
text(log(combined$land[criteria]), log(combined$headofcows[criteria]), labels="New Zealand", pos=2, cex=0.8)

Cows and Land

The observant among you might notice there are domain codes, element codes and item codes. To get the ones I wanted, I went to the FAOSTAT data download area

http://faostat3.fao.org/download/Q/QL/E

and I selected what I wanted in the way of categories. Then I chose the preview option on the screen, and just above and to the right of the preview table in the lower part of the screen is a Show Options drop down menu. I switched on codes in that and I could see the Domain Code, Element Code, and Item Code for the data I wanted, and I could put that information into the script above.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s