Skip to content

Commit

Permalink
Add coffee map example (geocompx#145)
Browse files Browse the repository at this point in the history
* Add coffee map example

* Update coffee data example

* Add variable name

* Update vignette code


Former-commit-id: be27f22
Former-commit-id: 6d13478
  • Loading branch information
Robinlovelace authored Jan 26, 2018
1 parent c5960dc commit 85842f2
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 0 deletions.
65 changes: 65 additions & 0 deletions extdata/coffee-data-messy.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
Monthly export statistics - November 2017,,,,,,
In thousand 60kg bags,,,,,,
,November 2016,November 2017,% change,October - November,,
,,,,2016/17,2017/18,% change
TOTAL,9 930,9 019,-9.2%,19 862,17 615,-11.3%
Arabicas,6 410,6 060,-5.5%,12 736,11 836,-7.1%
Colombian Milds,1 437,1 272,-11.5%,2 752,2 473,-10.1%
Other Milds,1 590,1 734,9.1%,3 158,3 243,2.7%
Brazilian Naturals,3 383,3 054,-9.7%,6 826,6 120,-10.3%
Robustas,3 520,2 959,-15.9%,7 127,5 779,-18.9%
Angola,0,0,,0,0,
Bolivia,3,4,42.5%,5,8,48.9%
Brazil,3 277,2 786,-15.0%,6 640,5 663,-14.7%
Burundi,37,38,3.0%,66,72,8.5%
Cameroon,8,6,-21.8%,15,18,16.9%
Central African Republic,0,0,,0,0,
"Congo, Dem. Rep. of",4,12,240.9%,7,24,267.7%
Colombia,1 330,1 169,-12.1%,2 560,2 293,-10.5%
Costa Rica,28,32,14.6%,71,46,-34.8%
Côte d'Ivoire,114,130,14.4%,165,202,22.1%
Cuba,0,0,,0,0,
Dominican Republic,1,0,,2,2,49.8%
Ecuador,87,62,-28.2%,192,133,-30.8%
El Salvador,5,8,54.4%,16,23,41.4%
Ethiopia,215,283,32.1%,424,560,31.9%
Gabon,0,0,,0,0,
Ghana,1,1,17.2%,2,2,17.2%
Guatemala,58,70,20.9%,105,130,23.8%
Honduras,149,165,11.2%,214,217,1.7%
India,453,566,25.0%,887,1 014,14.4%
Indonesia,742,360,-51.5%,1 643,960,-41.6%
Jamaica,0,1,,1,1,51.9%
Kenya,60,50,-16.2%,113,98,-13.4%
Liberia,0,0,,0,0,
Madagascar,3,5,39.4%,8,9,16.6%
Malawi,3,1,-60.2%,3,2,-40.5%
Mexico,151,220,45.6%,340,420,23.5%
Nepal,0,0,,0,0,
Nicaragua,42,45,7.1%,97,99,2.1%
Panama,3,3,13.6%,8,6,-27.4%
Papua New Guinea,114,74,-35.1%,256,161,-37.2%
Paraguay,0,0,,0,0,
Peru,585,625,6.8%,1 175,1 228,4.5%
Philippines,2,0,,5,0,
Rwanda,36,42,16.9%,75,82,9.8%
Sierra Leone,1,3,114.4%,3,6,86.8%
Tanzania,81,66,-18.1%,150,137,-8.7%
Thailand,39,16,-59.5%,80,32,-60.0%
Timor-Leste,14,2,-85.3%,25,4,-83.7%
Togo,2,3,0.1%,4,5,19.1%
Uganda,408,443,8.7%,617,825,33.7%
Venezuela,0,0,,0,0,
Vietnam,1 844,1 700,-7.8%,3 817,3 075,-19.4%
Yemen,4,1,-82.8%,10,2,-84.6%
Zambia,3,0,,4,0,
Zimbabwe,1,1,-47.8%,2,1,-38.2%
Others,23,26,12.7%,55,56,1.2%
Note: Group sub-totals take into account the corresponding share of each type of coffee exported by countries that produce and,,,,,,
"export both Arabica and Robusta in significant volumes. It should be noted that, where applicable, an Arabica/Robusta ratio of",,,,,,
50/50 has been used to convert processed coffee into Green Bean Equivalent (GBE),,,,,,
"A figure of 0 in the table can mean a volume of less than 500 bags, due to rounding. Full data in Excel format are available to paid",,,,,,
subscribers,,,,,,
Next update: 31 January 2018,,,,,,
 International Coffee Organization,,,,,,

59 changes: 59 additions & 0 deletions extdata/coffee-data.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name_long,y16,y17
Colombian Milds,1437,1272
Other Milds,1590,1734
Brazilian Naturals,3383,3054
Robustas,3520,2959
Angola,0,0
Bolivia,3,4
Brazil,3277,2786
Burundi,37,38
Cameroon,8,6
Central African Republic,0,0
"Congo, Dem. Rep. of",4,12
Colombia,1330,1169
Costa Rica,28,32
Côte d'Ivoire,114,130
Cuba,0,0
Dominican Republic,1,0
Ecuador,87,62
El Salvador,5,8
Ethiopia,215,283
Gabon,0,0
Ghana,1,1
Guatemala,58,70
Honduras,149,165
India,453,566
Indonesia,742,360
Jamaica,0,1
Kenya,60,50
Liberia,0,0
Madagascar,3,5
Malawi,3,1
Mexico,151,220
Nepal,0,0
Nicaragua,42,45
Panama,3,3
Papua New Guinea,114,74
Paraguay,0,0
Peru,585,625
Philippines,2,0
Rwanda,36,42
Sierra Leone,1,3
Tanzania,81,66
Thailand,39,16
Timor-Leste,14,2
Togo,2,3
Uganda,408,443
Venezuela,0,0
Vietnam,1844,1700
Yemen,4,1
Zambia,3,0
Zimbabwe,1,1
Others,23,26
Note: Group sub-totals take into account the corresponding share of each type of coffee exported by countries that produce and,NA,NA
"export both Arabica and Robusta in significant volumes. It should be noted that, where applicable, an Arabica/Robusta ratio of",NA,NA
50/50 has been used to convert processed coffee into Green Bean Equivalent (GBE),NA,NA
"A figure of 0 in the table can mean a volume of less than 500 bags, due to rounding. Full data in Excel format are available to paid",NA,NA
subscribers,NA,NA
Next update: 31 January 2018,NA,NA
 International Coffee Organization,NA,NA
19 changes: 19 additions & 0 deletions vignettes/coffee-map.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
library(tidyverse)
library(spData)
library(sf)
# found by searching for "global coffee data"
# u = "http://www.ico.org/prices/m1-exports.pdf"
# download.file(u, "data.pdf")
# install.packages("pdftables") # also requires an api key
# pdftables::convert_pdf(input_file = "data.pdf", output_file = "extdata/coffee-data-messy.csv")
d = read_csv("extdata/coffee-data-messy.csv")
coffee_data = slice(d, -c(1:5)) %>%
select(name_long = 1, y16 = 2, y17 = 3) %>%
mutate_at(2:3, str_replace, " ", "") %>%
mutate_at(2:3, as.integer)
write_csv(coffee_data, "extdata/coffee-data.csv")
world_coffee = left_join(world, coffee_data)
plot(world_coffee[c("y16", "y17")])
# library(tmap)
# qtm(world_coffee, "y17", fill.title = "Thousand 60kg bags")
# tmap_mode("view") # for an interactive version

0 comments on commit 85842f2

Please sign in to comment.