2024-06-05

Leveraging a rich dataset encompassing over 94 countries sourced from Kaggle, we’ll utilize R to pinpoint the top ten global coffee producers of 2023, both for domestic consumption and export. Subsequently, we’ll distill a concise dataset reflecting their performance over the past decade and craft an interactive ShinyApp showcasing this trend through a dynamic histogram.

Dive into the intricate dynamics of coffee production and consumption with our preliminary visual analysis App.

The dataset may be accessed here. (Original dataset source: Kaggle Coffee Dataset)

Let’s start by getting and cleaning this Coffee data

library(dplyr); library(reshape2); library(lattice)
df<-read.csv("https://raw.githubusercontent.com/dawit3000/Data/main/psd_coffee.csv")
#Who were top ten "Coffee Arabica" producers in 2023?
df_10<-filter(df, df$Year == 2023)
df_10<-arrange(df_10, desc(df_10$Arabica.Production)) 
df_10 <- unique(df_10$Country)[1:10] 
##Filter df using d_10. This data is for all years (not just 2023)
df<-filter(df, df$Country %in% df_10)
## dcast and choose columns of interest 
df<-dcast(df, Country ~ Year, value.var = "Arabica.Production")
df<-df[, c(1, 56:65)]
# transpose and sharpen for convenience
df <- as.data.frame(t(df))
colnames(df) <- df[1, ]
df <- df[-1, ]
i=1
for (i in 1: length(df[1,])) {
  df[,i]<-as.numeric(df[,i])
}
#Rely on this data for UI and Server
Coffee <-df

show(Coffee)
##      Brazil China Colombia Costa Rica Ethiopia Guatemala Honduras Mexico
## 2014  37300  2125    13300       1400     6475      3125     5100   2980
## 2015  36100  1900    14000       1625     6510      3125     5300   2125
## 2016  45600  1950    14600       1300     6943      3400     7510   3100
## 2017  39500  1950    13825       1525     7055      3600     7600   3800
## 2018  49700  1925    13870       1250     7350      3520     7100   3100
## 2019  42000  2000    14100       1466     7475      3515     5200   3150
## 2020  49700  1700    13400       1472     7600      3810     6500   3000
## 2021  36400  1700    11800       1215     8150      3410     4800   3200
## 2022  39800  1600    10700       1425     7300      3150     5700   3000
## 2023  44900  1700    11500       1440     8350      3305     6500   3545
##      Nicaragua Peru
## 2014      2100 2900
## 2015      2100 3500
## 2016      2600 4225
## 2017      2700 4375
## 2018      2900 4390
## 2019      2675 3925
## 2020      2550 3369
## 2021      2780 4200
## 2022      2500 3400
## 2023      2500 4200

Documentation

  • The end product is here deployed at ShinyApps.io

  • This App reactively renders bar-graphs of World’s Top 10 Coffee Arabica Producers of 2023, and their last 10 years trajectory

  • Both UI and Server codes of the app are pasted in app.R as one file

  • Users can directly ran the single app.R file OR may copy and paste segments in UI.R and Server.R files as two different files, with the data producing code pasted at the beginning of each code.

More info available here at the App’s project site