About Dataset


The data comes from nu3 and was contributed by Kasia Kulma in Tidytuesday.

More Information About Dataset.

Loading Library and Data


library(tidyverse)
library(knitr)
library(skimr)
library(echarts4r)

food_consumption <- read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2020/2020-02-18/food_consumption.csv')

I used several packages to help me do this task. That is Tidyverse, maps, janitor, skimr and knitr.

Data Preparation


food_consumption %>%
  head(10) %>%
  kable()
country food_category consumption co2_emmission
Argentina Pork 10.51 37.20
Argentina Poultry 38.66 41.53
Argentina Beef 55.48 1712.00
Argentina Lamb & Goat 1.56 54.63
Argentina Fish 4.36 6.96
Argentina Eggs 11.39 10.46
Argentina Milk - inc. cheese 195.08 277.87
Argentina Wheat and Wheat Products 103.11 19.66
Argentina Rice 8.77 11.22
Argentina Soybeans 0.00 0.00

Summary


Numeric Variable

food_consumption %>% 
  skim() %>%
  yank('numeric') %>% 
  select(-p0, -p25, -p75, -p100) %>%
  kable() 
skim_variable n_missing complete_rate mean sd p50 hist
consumption 0 1 28.11041 49.81804 8.89 ▇▁▁▁▁
co2_emmission 0 1 74.38399 152.09857 16.53 ▇▁▁▁▁

Character Variable

food_consumption %>% 
  skim() %>%
  yank('character') %>% 
  select(-whitespace, -empty) %>%
  kable()
skim_variable n_missing complete_rate min max n_unique
country 0 1 3 22 130
food_category 0 1 4 24 11

Data Exploration


How about relation between consumption vs. emmission in every food category?

food_consumption %>%
 gather(key = "feature", value = "value", -food_category, -country) %>%
 mutate(feature = str_to_title(feature %>% str_replace("_", " "))) %>% 
 ggplot() +
 geom_bar(aes(x = feature, y = value, fill = feature), stat = "identity") +
 facet_wrap(~food_category, scales = "free") +
 theme(legend.position = "bottom",
       axis.text.x = element_blank()) + 
 labs(x = "Features",
      y = element_blank(),
      fill = "Feature")

Beef and Milk-inc, Cheese produce CO2 emmission most higher than other food category.

food_consumption %>%
  gather(key = "feature", value = "value", -food_category, -country) %>%
  mutate(feature = str_to_title(feature %>% str_replace("_", " "))) %>%
  ggplot() +
  geom_density(aes(value, fill=feature, alpha = 0.7)) +
  facet_wrap(~food_category, scales = "free") +
  scale_x_log10() +
  theme(legend.position = "bottom") +
  labs(x = "Features",
       y = element_blank(),
       fill = "Feature")

Soybean and Wheat products have lower CO2 emissions than their consumption. Table of the relationship between total food consumption and total food emmission is shown below.

food_consumption %>%
 group_by(food_category) %>%
 summarise(total_consumption = sum(consumption),
           total_co2emmission = sum(co2_emmission)) %>%
 arrange(-total_consumption) %>%
 kable()
food_category total_consumption total_co2emmission
Milk - inc. cheese 16350.71 23290.00
Wheat and Wheat Products 9301.44 1773.78
Rice 3818.77 4886.91
Poultry 2758.50 2963.16
Fish 2247.32 3588.22
Pork 2096.08 7419.11
Beef 1576.04 48633.26
Eggs 1061.29 974.95
Nuts inc. Peanut Butter 537.84 951.99
Lamb & Goat 338.02 11837.38
Soybeans 111.87 50.35

Consumption Map

map <- food_consumption %>% 
  group_by(country) %>%
  summarise(total_consumption = sum(consumption),
            total_co2emmission = sum(co2_emmission)) %>%
  arrange(-total_consumption) %>%
  mutate(country = recode_factor (country,
                                  `USA` = "United States",
                                  `Czech Republic`= "Czech Rep.",
                                  `South Korea`= "Korea"))

map %>%
  e_charts(country) %>%
  e_map(total_consumption) %>%
  e_visual_map(min=0, 
               max=700) %>%
  e_title("\nTotal Consumption by Country \n (kg/person/year)\n", left = "center") %>%
  e_theme("auritus")
map %>% 
  head(10) %>% kable()
country total_consumption total_co2emmission
Finland 639.79 1464.63
Lithuania 555.01 868.90
Sweden 550.00 1527.03
Netherlands 534.17 1292.82
Albania 532.73 1777.85
Ireland 518.65 1459.67
Switzerland 514.90 1356.75
Italy 513.98 1206.33
Denmark 499.07 1498.18
Luxembourg 497.90 1598.41

CO2 Emmission Map

map %>%
  e_charts(country) %>%
  e_map(total_co2emmission) %>%
  e_visual_map(min = 0, 
               max = 2200) %>%
  e_title("\nTotal CO2 emissions by Country \n (kg CO2/person/year)\n", 
          left = "center") %>%
  e_theme("essos")
map %>% 
  arrange(-total_co2emmission) %>%
  head(10) %>% kable()
country total_consumption total_co2emmission
Argentina 429.41 2172.40
Australia 465.09 1938.66
Albania 532.73 1777.85
New Zealand 360.92 1750.95
Iceland 472.31 1731.36
United States 491.15 1718.86
Uruguay 433.60 1634.91
Brazil 355.16 1616.73
Luxembourg 497.90 1598.41
Kazakhstan 468.10 1575.08

Thank You

Amri Rohman.
Sidoarjo, East Java, ID