Saskatchewan Lentil Production and Exports
Graphs of lentil production and exports using SKAG data
Data
Prepare Data
# devtools::install_github("derekmichaelwright/agData")
library(agData)
library(gganimate)
<- c("darkred","darkgreen","darkorange","darkblue","grey")
myCs_Regions <- c("darkgreen", "darkgoldenrod3", "darkred", "black")
myCs_Lens <- c("Large Green Lentils","Small Green Lentils",
myCrops "Red Lentils","Other Lentils")
<- "www.dblogr.com/ or derekmichaelwright.github.io/dblogr/ | Data: STATCAN"
myCaption #
<- agData_STATCAN_Crops %>%
x1 filter(Item == "Lentils", Measurement == "Production",
== "Saskatchewan")
Area <- read.csv("lentil_timeline.csv")
x2 <- full_join(x1, x2, by = "Year") %>%
d1 mutate(Value = ifelse(is.na(Value), 0, Value))
#
<- agData_SKAG_Specialty_Crops %>%
d2 filter(grepl("Lentil", Item), Item != "Total Lentils") %>%
mutate(Item = factor(Item, levels = myCrops))
#
<- agData_SKAG_Lentil_Exports %>%
d3 left_join(agData_FAO_Country_Table, by = c("Area"="Country"))
Timeline
# Plot
<- ggplot(d1, aes(x = Year)) +
mp geom_segment(aes(xend = Year, y = Value / 1000000, yend = Nudge_y), alpha = 0.7) +
geom_label(aes(label = Event, y = Nudge_y, fill = Type),
size = 3, alpha = 0.6, hjust = 1) +
geom_area(aes(y = Value / 1000000), fill = "darkgreen", alpha = 0.7, color = I("Black")) +
scale_fill_manual(values = c("darkred", "darkorange", "steelblue")) +
scale_x_continuous(breaks = seq(1970,2020, by = 10),
limits = c(1935, 2021), expand = c(0,0)) +
scale_y_continuous(expand = c(0,0), limits = c(0,4)) +
theme_agData(legend.position = "none",
panel.grid.major.x = element_blank(),
panel.grid.minor.x = element_blank()) +
labs(title = "Saskatchewan Lentil Industry", x = NULL,
y = "Production (Million Tonnes)", caption = myCaption)
ggsave("lentil_saskatchewan_1.png", mp, width = 6, height = 4)
Bar Chart Racer
# Prep data
<- d3 %>%
xx filter(Area != "World") %>%
mutate(Date = Year,
Year = as.numeric(substr(Year, 1, 4)))
# Plot
<- ggplot(xx, aes(xmin = 0, xmax = Value / 1000000,
mp ymin = Rank - 0.45, ymax = Rank + 0.45, y = Rank,
fill = Area)) +
geom_rect(alpha = 0.7, color = "black") +
scale_fill_manual(values = alpha(agData_Colors, 0.75)) +
scale_x_continuous(limits = c(-0.6,1), breaks = seq(0, 3, by=0.5)) +
geom_text(col = "black", hjust = "right", aes(label = Area), x = -0.1) +
scale_y_reverse() +
theme_agData(legend.position = "none",
axis.text.y = element_blank(),
axis.ticks.y = element_blank()) +
labs(title = "Saskatchewan Lentil Exports - {round(frame_time)}",
x = "Million Tonnes (3 year moving average)",
y = NULL, caption = myCaption) +
transition_time(Year)
anim_save("lentil_saskatchewan_gif_01.gif", mp,
nframes = 600, fps = 30, end_pause = 120,
width = 900, height = 600, res = 150)
Lentil Production
All Data
# Plot
<- ggplot(d2, aes(x = Year, y = Value, color = Item)) +
mp geom_line(size = 1, alpha = 0.7) +
facet_wrap(Measurement + Unit ~ ., scales = "free_y") +
theme_agData(legend.position = "bottom") +
scale_color_manual(name = NULL, values = myCs_Lens) +
labs(title = "Lentil - Production",
y = NULL, x = NULL, caption = myCaption)
ggsave("lentil_saskatchewan_2_01.png", width = 8, height = 6)
Area Harvested By Type
# Prep data
<- d2 %>% filter(Measurement == "Area Harvested")
xx # Plot
<- ggplot(xx, aes(x = Year, y = Value / 1000000, color = Item)) +
mp geom_line(size = 1.5, alpha = 0.7) +
facet_wrap(Item ~ ., scales = "free_y") +
scale_color_manual(name = NULL, values = myCs_Lens) +
theme_agData(legend.position = "bottom") +
labs(title = "Lentil - Area Harvested",
y = "Million Hectares", x = NULL, caption = myCaption)
ggsave("lentil_saskatchewan_2_02.png", width = 8, height = 6)
Production By Type
# Prep data
<- d2 %>% filter(Measurement == "Production")
xx # Plot
<- ggplot(xx, aes(x = Year, y = Value / 1000000, color = Item)) +
mp geom_line(size = 1.5, alpha = 0.7) +
facet_wrap(Item ~ ., scales = "free_y") +
scale_color_manual(name = NULL, values = myCs_Lens) +
theme_agData(legend.position = "bottom") +
labs(title = "Lentil - Production",
y = "Million Tonnes", x = NULL, caption = myCaption)
ggsave("lentil_saskatchewan_2_03.png", width = 8, height = 6)
Production & Area
# Prep data
<- d2 %>% filter(Measurement %in% c("Production", "Area Harvested"))
xx # Plot
<- ggplot(xx, aes(x = Year, y = Value / 1000000, fill = Item)) +
mp geom_col(position = "stack", color = "black", alpha = 0.7) +
facet_wrap(paste0(Measurement, " (", Unit, ")") ~ ., scales = "free_y") +
scale_fill_manual(name = NULL, values = myCs_Lens) +
theme_agData(legend.position = "bottom") +
labs(title = "Lentil - Saskatchewan",
y = "Million", x = NULL, caption = myCaption)
ggsave("lentil_saskatchewan_2_04.png", width = 8, height = 4)
Exports
World
# Prep data
<- d3 %>% filter(Area == "World")
xx # Plot
<- ggplot(xx, aes(x = Year, y = Value / 1000)) +
mp geom_col(color = "black", fill = "darkgreen", alpha = 0.7) +
theme_agData(axis.text.x = element_text(angle = 45, hjust = 1)) +
labs(title = "Saskatchewan Lentil Exports",
y = "Thousand Tonnes", x = NULL, caption = myCaption)
ggsave("lentil_saskatchewan_3_01.png", width = 6, height = 4)
All Data
# Prep data
<- c("Africa", "Americas", "Asia", "Europe", "Other")
myRegions <- d3 %>%
xx arrange(desc(Value)) %>%
mutate(Area = factor(Area, levels = unique(c(.$Area[.$Area!="Other"],"Other"))),
Region = ifelse(Area == "Other", "Other", Region))
# Plot
<- ggplot(xx, aes(x = Year, y = Value / 1000, fill = Region)) +
mp geom_col(color = "black", alpha = 0.7) +
facet_wrap(Area ~ ., scales = "free_y", ncol = 4) +
scale_fill_manual(name = NULL, values = myCs_Regions, breaks = myRegions) +
theme_agData(legend.position = "bottom",
axis.text.x = element_text(angle = 45, hjust = 1)) +
labs(title = "Saskatchewan Lentil Exports",
y = "Thousand Tonnes", x = NULL, caption = myCaption)
ggsave("lentil_saskatchewan_3_02.png", width = 14, height = 18)
2018-2019
# Prep data
<- d3 %>%
xx filter(Area != "World", Year == "2018-2019") %>%
arrange(desc(Value)) %>%
mutate(Area = factor(Area, levels = c(.$Area[.$Area!="Other"],"Other")),
Region = ifelse(Area == "Other", "Other", Region))
# Plot
<- ggplot(xx, aes(x = Area, y = Value / 1000, group = Area, fill = Region)) +
mp geom_col(alpha = 0.7, color = "black") +
facet_wrap(Year ~ ., scales = "free_y", ncol = 8) +
scale_fill_manual(name = NULL, values = myCs_Regions) +
theme_agData(axis.text.x = element_text(angle = 45, hjust = 1)) +
labs(title = "Saskatchewan Lentil Exports",
y = "Thousand Tonnes", x = NULL, caption = myCaption)
ggsave("lentil_saskatchewan_3_03.png", width = 6, height = 4)
2019-2020
# Prep data
<- d3 %>%
xx filter(Area != "World", Year == "2019-2020") %>%
arrange(desc(Value)) %>%
mutate(Area = factor(Area, levels = c(.$Area[.$Area!="Other"],"Other")),
Region = ifelse(Area == "Other", "Other", Region))
# Plot
<- ggplot(xx, aes(x = Area, y = Value / 1000, group = Area, fill = Region)) +
mp geom_col(alpha = 0.7, color = "black") +
facet_wrap(Year ~ ., scales = "free_y", ncol = 8) +
scale_fill_manual(name = NULL, values = myCs_Regions) +
theme_agData(axis.text.x = element_text(angle = 45, hjust = 1)) +
labs(title = "Saskatchewan Lentil Exports",
y = "Thousand Tonnes", x = NULL, caption = myCaption)
ggsave("lentil_saskatchewan_3_04.png", width = 6, height = 4)
2021-2022
# Prep data
<- d3 %>%
xx filter(Area != "World", Year == "2020-2021") %>%
arrange(desc(Value)) %>%
mutate(Area = factor(Area, levels = c(.$Area[.$Area!="Other"],"Other")),
Region = ifelse(Area == "Other", "Other", Region))
# Plot
<- ggplot(xx, aes(x = Area, y = Value / 1000, group = Area, fill = Region)) +
mp geom_col(alpha = 0.7, color = "black") +
facet_wrap(Year ~ ., scales = "free_y", ncol = 8) +
scale_fill_manual(name = NULL, values = myCs_Regions) +
theme_agData(axis.text.x = element_text(angle = 45, hjust = 1)) +
labs(title = "Saskatchewan Lentil Exports", x = NULL,
y = "Thousand Tonnes", caption = myCaption)
ggsave("lentil_saskatchewan_3_05.png", width = 6, height = 4)