Import/Export by Area
Graphs of of import/export by area using FAO data
Prepare Data
# devtools::install_github("derekmichaelwright/agData")
library(agData)
#
myCaption <- "derekmichaelwright.github.io/dblogr/ | Data: FAOSTAT"
Import/Export
Ploting function
xx <- agData_FAO_Trade_Quantity %>%
filter(Area == "Canada")
# Create plotting functions
ggIEA <- function(myArea = "Canada") {
# Prep data
myItems <- c("Cereals", "Pulses", "Oilseeds", "Roots and Tubers", "Fruit", "Vegetables")
myColors <- c("steelblue", "darkred")
xx <- agData_FAO_Trade_Quantity %>%
filter(Area == myArea, Item %in% myItems) %>%
mutate(Measurment = gsub(" Quantity", "", Measurement),
Item = factor(Item, levels = myItems))
# Plot
ggplot(xx, aes(x = Year, y = Value / 1000000, fill = Measurement,
group = Measurement)) +
geom_bar(stat = "identity", position = "dodge",
color = "black", lwd = 0.2, alpha = 0.7) +
facet_wrap(Item ~ ., scales = "free_y", ncol = 2) +
scale_fill_manual(name = NULL, values = myColors) +
scale_x_continuous(breaks = seq(1960, 2020, by = 10)) +
theme_agData(legend.position = "bottom",
axis.text.x = element_text(angle = 45, hjust = 1)) +
labs(title = myArea, y = "Million Tonnes",
x = NULL, caption = myCaption)
}
Canada
Mexico
Russia
Ukraine
Germany
Netherlands
mp <- ggIEA(myArea = "Netherlands")
ggsave("import_export_1_netherlands.png", mp, width = 10, height = 6)
Africa
Europe
2019
Ploting function
#
ggIEAY <- function(myArea = "Canada", myYear = 2017) {
# Prep data
myItems <- c("Cereals", "Pulses", "Oilseeds", "Roots and Tubers", "Fruit", "Vegetables")
myColors <- c("darkgreen", "darkred", "darkgoldenrod2", "darkblue", "steelblue", "purple4")
xx <- agData_FAO_Trade_Quantity %>%
filter(Area == myArea, Year == myYear, Item %in% myItems) %>%
mutate(Measurment = gsub(" Quantity", "", Measurement),
Item = factor(Item, levels = myItems))
# Plot
ggplot(xx, aes(x = Measurement, y = Value / 1000000,
fill = Item, alpha = Measurement)) +
geom_bar(stat = "identity", color = "black") +
facet_wrap(. ~ Item, ncol = 3, scale = "free_y") +
scale_fill_manual(values = myColors) +
scale_alpha_manual(values = c(0.5,0.8)) +
theme_agData(legend.position = "none",
axis.text.x = element_text(angle = 45, hjust = 1)) +
labs(title = paste(myArea, myYear), y = "Million Tonnes",
x = NULL, caption = myCaption)
}
Canada
mp <- ggIEAY(myArea = "Canada", myYear = 2019)
ggsave("import_export_2_canada.png", mp, width = 5, height = 5)
USA
mp <- ggIEAY(myArea = "USA", myYear = 2019)
ggsave("import_export_2_usa.png", mp, width = 5, height = 5)
Russia
mp <- ggIEAY(myArea = "Russia", myYear = 2019)
ggsave("import_export_2_russia.png", mp, width = 5, height = 5)
Ukraine
mp <- ggIEAY(myArea = "Ukraine", myYear = 2019)
ggsave("import_export_2_ukraine.png", mp, width = 5, height = 5)
Germany
mp <- ggIEAY(myArea = "Germany", myYear = 2019)
ggsave("import_export_2_germany.png", mp, width = 5, height = 5)
India
mp <- ggIEAY(myArea = "India", myYear = 2019)
ggsave("import_export_2_india.png", mp, width = 5, height = 5)