Wheat Production
Graphs of wheat production using FAO data
Prepare Data
# devtools::install_github("derekmichaelwright/agData")
library(agData)
# Prep data
<- "www.dblogr.com/ or derekmichaelwright.github.io/dblogr/ | Data: FAO"
myCaption #
<- agData_FAO_Crops %>% filter(Item == "Wheat") dd
PDF - All Wheat Data
# Prep data
<- c("darkgreen", "darkred", "darkgoldenrod2")
myColors <- c("World",
myAreas unique(agData_FAO_Region_Table$Region),
unique(agData_FAO_Region_Table$SubRegion),
unique(agData_FAO_Country_Table$Country))
<- dd %>%
xx mutate(Value = ifelse(Measurement %in% c("Area Harvested", "Production"),
/ 1000000, Value / 1000),
Value Unit = plyr::mapvalues(Unit, c("Hectares", "Tonnes", "kg/ha"),
c("Million Hectares", "Million Tonnes", "Tonnes/ Hectare")))
<- myAreas[myAreas %in% xx$Area]
myAreas # Plot
pdf("figures_wheat_fao.pdf", width = 12, height = 4)
for(i in myAreas) {
print(ggplot(xx %>% filter(Area == i)) +
geom_line(aes(x = Year, y = Value, color = Measurement),
size = 1.5, alpha = 0.7) +
facet_wrap(. ~ Measurement + Unit, ncol = 3, scales = "free_y") +
theme_agData(legend.position = "none",
axis.text.x = element_text(angle = 45, hjust = 1)) +
scale_color_manual(values = myColors) +
scale_x_continuous(breaks = seq(1960, 2020, by = 5) ) +
labs(title = i, y = NULL, x = NULL, caption = myCaption) )
}dev.off()
Production
Regions
# Prep data
<- c("darkred", "steelblue", "darkgreen", "darkblue", "darkorange")
myColors <- c("Africa", "Oceania", "Americas", "Europe", "Asia" )
myAreas <- dd %>%
xx filter(Area %in% myAreas,
== "Production", Year == 2019) %>%
Measurement mutate(Area = factor(Area, levels = myAreas)) %>%
arrange(desc(Area)) %>%
mutate(Prop = round(100 * Value / sum(Value)),
Label = ifelse(Prop > 5, Prop, NA),
ypos = cumsum(Prop) - 0.5 * Prop )
# Plot
<- ggplot(xx, aes(x = "", y = Prop, fill = Area)) +
mp geom_col(width = 1, color = "black", alpha = 0.7, lwd = 1) +
coord_polar("y", start = 0) +
geom_label(aes(y = ypos, label = Label), nudge_x = 0.1,
fill = "white", color = "black", alpha = 0.8, size = 6) +
scale_fill_manual(name = NULL, values = myColors) +
theme_agData_pie() +
labs(title = "Wheat Production 2019", caption = myCaption)
ggsave("wheat_01.png", mp, width = 6, height = 4)
SubRegions
# Prep data
<- c("darkgreen", "darkblue", "darkred", "darkorange", "steelblue")
myColors <- dd %>%
xx filter(Measurement == "Production", Year == 2019,
%in% agData_FAO_Region_Table$SubRegion) %>%
Area left_join(select(agData_FAO_Region_Table, Area=SubRegion, Region),
by = "Area")
# Plot
<- ggplot(xx, aes(x = Area, y = Value / 1000000, fill = Region)) +
mp geom_col(color = "black", alpha = 0.7) +
facet_grid(. ~ Region, scales = "free_x", space = "free_x") +
scale_fill_manual(values = myColors) +
theme_agData(legend.position = "none",
axis.text.x = element_text(angle = 45, hjust = 1)) +
labs(title = "Wheat Production 2019", x = NULL,
y = "Million Tonnes", caption = myCaption)
ggsave("wheat_02.png", mp, width = 6, height = 4)
Russia & Ukraine
All Years
# Prep data
<- c("darkgreen", "darkred", "steelblue", "darkorange")
myColors <- c(c("Rest of World", "Russia", "Ukraine", "USSR"))
myAreas <- dd %>%
xx filter(Measurement == "Production",
%in% agData_FAO_Country_Table$Country)
Area <- xx %>% filter(Area %in% myAreas)
x1 <- xx %>% filter(!Area %in% myAreas) %>%
x2 group_by(Year) %>%
summarise(Value = sum(Value)) %>%
mutate(Area = "Rest of World")
<- bind_rows(x1, x2) %>%
xx mutate(Area = factor(Area, levels = myAreas))
# Plot
<- ggplot(xx, aes(x = Year, y = Value / 1000000, fill = Area)) +
mp geom_col(color = "black", alpha = 0.7) +
scale_fill_manual(name = NULL, values = myColors) +
theme_agData() +
labs(title = "Global Wheat Production", x = NULL,
y = "Million Tonnes", caption = myCaption)
ggsave("wheat_03.png", mp, width = 6, height = 4)
2019
# Prep data
<- xx %>%
x1 filter(Year == 2019) %>%
arrange(desc(Area)) %>%
mutate(Prop = round(100 * Value / sum(Value)),
ypos = cumsum(Prop) - 0.5 * Prop )
# Plot
<- ggplot(x1, aes(x = "", y = Prop, fill = Area)) +
mp geom_bar(stat = "identity", width = 1,
color = "black", alpha = 0.7, lwd = 1) +
coord_polar("y", start = 0) +
geom_label(aes(y = ypos, label = Prop), nudge_x = 0.3,
fill = "white", color = "black", alpha = 0.8, size = 6) +
scale_fill_manual(name = NULL, values = myColors) +
theme_agData_pie() +
labs(title = "Wheat Production 2019", caption = myCaption)
ggsave("wheat_04.png", mp, width = 6, height = 4)
1965
# Prep data
<- c("darkgreen", "darkorange")
myColors <- xx %>%
x1 filter(Year == 1965) %>%
arrange(desc(Area)) %>%
mutate(Prop = round(100 * Value / sum(Value)),
ypos = cumsum(Prop) - 0.5 * Prop )
# Plot
<- ggplot(x1, aes(x = "", y = Prop, fill = Area)) +
mp geom_col(width = 1, color = "black", alpha = 0.7, lwd = 1) +
coord_polar("y", start = 0) +
geom_label(aes(y = ypos, label = Prop), nudge_x = 0.3,
fill = "white", color = "black", alpha = 0.8, size = 6) +
scale_fill_manual(name = NULL, values = myColors) +
theme_agData_pie() +
labs(title = "Wheat Production 1965", caption = myCaption)
ggsave("wheat_05.png", mp, width = 6, height = 4)