Saskatchewan Crop Production

Graphs of crop production in Saskatchewan using STATCAN data


Prepare Data

# devtools::install_github("derekmichaelwright/agData")
library(agData)
library(treemapify)
library(gganimate)
myCaption <- "www.dblogr.com/ or derekmichaelwright.github.io/dblogr/ | Data: STATCAN"
#
d1 <- agData_STATCAN_Crops %>% filter(Area == "Saskatchewan")
d2 <- agData_STATCAN_FarmLand_Use %>% filter(Area == "Saskatchewan")

PDF - All Crops

figures_crops_saskatchewan_statcan.pdf

# Prep data
myColors <- c("darkgreen", "darkorange", "darkred", 
              "antiquewhite4", "steelblue", "darkblue")
myMeasures <- c("Area Seeded", "Area Harvested", "Production", 
                "Yield", "Average Farm Price", "Total Farm Value")
xx <- d1 %>%
  mutate(Measurement = factor(Measurement, levels = myMeasures),
         Value = ifelse(Measurement != "Yield",
                        Value / 1000000, Value / 1000),
         Unit = plyr::mapvalues(Unit, c("Hectares", "Tonnes", "kg/ha"), 
                  c("Million Hectares", "Million Tonnes", "Tonnes/ Hectare")))
myCrops <- unique(xx$Item)
# Plot
pdf("figures_crops_saskatchewan_statcan.pdf", width = 10, height = 6)
for(i in myCrops) {
  xi <- xx %>% filter(Item == i)
  print(ggplot(xi, aes(x = Year, y = Value, color = Measurement)) +
    geom_line(size = 1.5, alpha = 0.7) +
    facet_wrap(. ~ Measurement, scales = "free_y", ncol = 3) +
    scale_color_manual(values = myColors) +
    scale_x_continuous(breaks = seq(1920, 2020, by = 20) ) +
    theme_agData(legend.position = "none", 
                 axis.text.x = element_text(angle = 45, hjust = 1)) +
    labs(title = i, y = NULL, x = NULL, caption = myCaption) )
}
dev.off()

1908 Vs. 1961 Vs. 2020

# Create function to determine top crops
cropList <- function(measurement, years) {
  # Prep data
  xx <- agData_STATCAN_Crops %>% 
    filter(Measurement == measurement, Year %in% years,
           Area == "Saskatchewan") %>%
    arrange(desc(Value)) %>% 
    pull(Item) %>% unique() %>% as.character()
  xx
}

Production

# Prep data
myCrops <- cropList(measurement = "Production", years = c(2020, 1961, 1908))
xx <- d1 %>% 
  filter(Measurement == "Production", Item %in% myCrops,
         Year %in% c(2020, 1961, 1908) ) %>%
  mutate(Item = factor(Item, levels = myCrops) )
# Plot
mp <- ggplot(xx, aes(x = Item, y = Value / 1000000, fill = Item)) + 
  geom_col(color = "Black", alpha = 0.7) + 
  facet_grid(Year ~ .) + 
  scale_fill_manual(values = agData_Colors) +
  theme_agData(legend.position = "none", 
               axis.text.x = element_text(angle = 45, hjust = 1)) + 
  labs(title = "Saskatchewan - Crop Production", 
       y = "Million Tonnes", x = NULL, caption = myCaption)
ggsave("crops_saskatchewan_01.png", mp, width = 7, height = 5)

Area Seeded

# Prep data
myCrops <- cropList(measurement = "Area Seeded", years = c(2020, 1961, 1908))
xx <- d1 %>% 
  filter(Measurement == "Area Seeded", Item %in% myCrops,
         Year %in% c(2020, 1961, 1908) ) %>%
  mutate(Item = factor(Item, levels = myCrops) )
# Plot
mp <- ggplot(xx, aes(x = Item, y = Value / 1000000, fill = Item)) + 
  geom_col(color = "Black", alpha = 0.7) + 
  facet_grid(Year ~ .) + 
  scale_fill_manual(values = c("antiquewhite4", agData_Colors)) +
  theme_agData(legend.position = "none", 
               axis.text.x = element_text(angle = 45, hjust = 1)) + 
  labs(title = "Saskatchewan - Area Seeded", x = NULL,
       y = "Million Hectares", caption = myCaption)
ggsave("crops_saskatchewan_02.png", mp, width = 7, height = 5)

Yields

# Prep data
myCrops <- cropList(measurement = "Yield", years = c(2020, 1961, 1908))[-1]
xx <- d1 %>% 
  filter(Measurement == "Yield", Item %in% myCrops,
         Year %in% c(2020, 1961, 1908) ) %>%
  mutate(Item = factor(Item, levels = myCrops) )
# Plot
mp <- ggplot(xx, aes(x = Item, y = Value / 1000, fill = Item)) + 
  geom_col(color = "Black", alpha = 0.7) + 
  facet_grid(Year ~ .) + 
  scale_fill_manual(values = agData_Colors) +
  theme_agData(legend.position = "none", 
               axis.text.x = element_text(angle = 45, hjust = 1)) + 
  labs(title = "Saskatchewan - Yield", x = NULL, 
       y = "Tonnes / Hectare", caption = myCaption)
ggsave("crops_saskatchewan_03.png", mp, width = 7, height = 5)

Bar Chart Racer

Production

# Prep data
xx <- d1 %>% 
    filter(!Item %in% c("Hemp","Sugar beets"),
           Measurement == "Production") %>% 
  group_by(Item) %>%
  mutate(Value = movingAverage(Value, n = 3)) %>%
  group_by(Year) %>%
  arrange(Year, -Value) %>%
  mutate(Rank = 1:n()) %>%
  filter(Rank < 15) %>% 
  arrange(desc(Year)) %>%
  mutate(Item = factor(Item, levels = unique(.$Item)))
# Plot
mp <- ggplot(xx, aes(xmin = 0, xmax = Value / 1000000, 
                     ymin = Rank - 0.45, ymax = Rank + 0.45, y = Rank, 
                     fill = Item)) + 
  geom_rect(alpha = 0.7, color = "black") + 
  scale_fill_manual(values = agData_Colors) +
  scale_x_continuous(limits = c(-4,max(xx$Value)/1000000),
                     breaks = seq(0, 18, by = 4),
                     minor_breaks = seq(0, 18, by = 2)) +
  geom_text(aes(label = Item), col = "black", hjust = 1, x = -0.2) +
  scale_y_reverse() +
  theme_agData(legend.position = "none",
               axis.text.y = element_blank(), 
               axis.ticks = element_blank(),
               panel.grid.major.y = element_blank(),
               panel.grid.minor.y = element_blank()) + 
  labs(title = paste("Saskatchewan - Production -", "{frame_time}"),
       x = "Million Tonnes", y = NULL, caption = myCaption) +
  transition_time(Year) 
anim_save("crops_saskatchewan_gif_01.gif", mp,
          nframes = 600, fps = 15, end_pause = 60, 
          width = 900, height = 600, res = 150)

Seeded Area

# Prep data
xx <- d1 %>% 
  filter(Measurement == "Area Seeded") %>% 
  group_by(Year) %>%
  arrange(Year, -Value) %>%
  mutate(Rank = 1:n()) %>%
  filter(Rank < 15) %>% 
  arrange(desc(Year)) %>%
  mutate(Item = factor(Item, levels = unique(.$Item)))
# Plot
mp <- ggplot(xx, aes(xmin = 0, xmax = Value / 1000000, 
                     ymin = Rank - 0.45, ymax = Rank + 0.45, y = Rank, 
                     fill = Item)) + 
  geom_rect(alpha = 0.7, color = "black") + 
  scale_fill_manual(values = agData_Colors) +
  scale_x_continuous(limits = c(-2,max(xx$Value)/1000000),
                     breaks = seq(0, 10, by = 2),
                     minor_breaks = seq(0, 10, by = 1)) +
  geom_text(aes(label = Item), col = "black", hjust = 1, x = -0.1) +
  scale_y_reverse() +
  theme_agData(legend.position = "none",
               axis.text.y = element_blank(), 
               axis.ticks = element_blank(),
               panel.grid.major.y = element_blank(),
               panel.grid.minor.y = element_blank()) + 
  labs(title = paste("Saskatchewan - Area Harvested -", "{frame_time}"),
       x = "Million Hectares", y = NULL, caption = myCaption) +
  transition_time(Year) 
anim_save("crops_saskatchewan_gif_02.gif", mp,
          nframes = 600, fps = 15, end_pause = 60, 
          width = 900, height = 600, res = 150)

Production of Major Crops

# Prep data
myCrops <- cropList(measurement = "Production", years = 2020)[c(1:8)]
myCrops <- c(myCrops, "Other")
x1 <- d1 %>% filter(Measurement == "Production", Item %in% myCrops) 
x2 <- d1 %>% filter(Measurement == "Production", !Item %in% myCrops) %>%
  group_by(Year) %>%
  summarise(Value = sum(Value, na.rm = T)) %>%
  ungroup() %>%
  mutate(Item = "Other")
xx <- bind_rows(x1, x2) %>%
  mutate(Item = factor(Item, levels = rev(myCrops)))
# Plot
mp <- ggplot(xx, aes(x = Year, y = Value / 1000000, fill = Item)) + 
  geom_col(alpha = 0.7, color = "black", lwd = 0.1) + 
  scale_fill_manual(name = NULL, values = agData_Colors[c(9:1)]) +
  scale_x_continuous(breaks = seq(1910, 2020, by=10), expand = c(0.01,0)) +
  guides(fill = guide_legend(override.aes = list(lwd = 0.4))) +
  theme_agData() + 
  labs(title = "Saskatchewan - Crop Production", x = NULL, 
       y = "Million Tonnes", caption = myCaption)
ggsave("crops_saskatchewan_04.png", mp, width = 8, height = 4)

Production By Decade

# Prep data
myCrops <- cropList(measurement = "Production", years = 2020)[c(1:8)]
myCrops <- c(myCrops, "Other")
x1 <- d1 %>% filter(Measurement == "Production", Item %in% myCrops) 
x2 <- d1 %>% filter(Measurement == "Production", !Item %in% myCrops) %>%
  group_by(Year) %>%
  summarise(Value = sum(Value, na.rm = T)) %>%
  ungroup() %>%
  mutate(Item = "Other")
xx <- bind_rows(x1, x2) %>%
  mutate(Item = factor(Item, levels = rev(myCrops)),
         Decade = floor(Year/10)*10)
x1 <- xx %>% filter(Year >= 1910, Year <= 2020) %>% 
  group_by(Item, Decade) %>%
  summarise(Value = mean(Value, na.rm = T)) %>%
  rename(Year=Decade) %>%
  mutate(Year = paste0(Year, "'s"))
x2 <- xx %>% filter(Year == 2021) %>% 
  mutate(Year = as.character(Year))
xx <- bind_rows(x1, x2) %>% 
  mutate(Year = factor(Year))
# Plot
mp <- ggplot(xx, aes(x = Year, y = Value / 1000000, fill = Item)) + 
  geom_col(alpha = 0.7, color = "black", lwd = 0.2) + 
  scale_fill_manual(name = NULL, values = agData_Colors[c(9:1)]) +
  guides(fill = guide_legend(override.aes = list(lwd = 0.4))) +
  theme_agData() + 
  labs(title = "Saskatchewan - Crop Production", 
       y = "Million Tonnes", x = NULL, caption = myCaption)
mp

ggsave("crops_saskatchewan_05.png", mp, width = 8, height = 4)

Droughts

# Prep data
myCrops <- cropList(measurement = "Production", years = 2020)[c(1:8)]
myCrops <- c(myCrops, "Other")
myYears <- c(1935,1936,1937,1938,1939, 1952,1953,1954,1955,1956, 
             1959,1960,1961,1962,1963, 1986,1987,1988,1989,1990, 
             2000,2001,2002,2003,2004, 2019,2020,2021,2022,2023)
myGroups <- c(rep(1:6, each = 5))
x1 <- d1 %>% filter(Measurement == "Production", Item %in% myCrops) 
x2 <- d1 %>% filter(Measurement == "Production", !Item %in% myCrops) %>%
  group_by(Year) %>%
  summarise(Value = sum(Value, na.rm = T)) %>%
  ungroup() %>%
  mutate(Item = "Other")
xx <- bind_rows(x1, x2) %>%
  filter(Year %in% myYears) %>%
  mutate(Item = factor(Item, levels = rev(myCrops)),
         Group = plyr::mapvalues(Year, myYears, myGroups))
# Plot
mp <- ggplot(xx, aes(x = Year, y = Value / 1000000, fill = Item)) + 
  geom_col(alpha = 0.7, color = "black", lwd = 0.3) + 
  facet_wrap(Group ~ . , ncol = 6, scales = "free") +
  scale_fill_manual(name = NULL, values = agData_Colors[c(9:1)]) +
  guides(fill = guide_legend(override.aes = list(lwd = 0.4))) +
  theme_agData(axis.text.x = element_text(angle = 45, hjust = 1),
               strip.text = element_blank()) + 
  labs(title = "Saskatchewan - Drought Years", x = NULL,
       y = "Million Tonnes", caption = myCaption)
ggsave("crops_saskatchewan_06.png", mp, width = 8, height = 4)

2020 vs 2021

# Prep data
xx <- xx %>% filter(Year %in% c(2020, 2021)) %>%
  mutate(Item = factor(Item, levels = myCrops),
         Year = factor(Year))
# Plot
mp <- ggplot(xx, aes(x = Item, y = Value / 1000000, 
                     fill = Item, alpha = Year)) + 
  geom_col(position = "dodge", color = "black") + 
  scale_fill_manual(values = agData_Colors, guide = F) +
  scale_alpha_manual(name = NULL, values = c(0.7, 0.3)) +
  theme_agData(legend.position = "bottom") + 
  labs(title = "Saskatchewan - Crop Production - 2020 vs. 2021", 
       y = "Million Tonnes", x = NULL, caption = myCaption)
ggsave("crops_saskatchewan_07.png", mp, width = 6, height = 4)

Yields 2020

# Prep data
myCrops <- cropList(measurement = "Yield", years = 2020)[-1]
xx <- d1 %>% 
  filter(Year == 2020, Measurement == "Yield", Item %in% myCrops) %>%
  mutate(Item = factor(Item, levels = myCrops) )
# Plot
mp <- ggplot(xx, aes(x = Item, y = Value / 1000, fill = Item)) + 
  geom_col(color = "Black", alpha = 0.7) + 
  facet_grid(Year ~ .) + 
  scale_fill_manual(values = agData_Colors) +
  theme_agData(legend.position = "none", 
               axis.text.x = element_text(angle = 45, hjust = 1)) + 
  labs(title = "Saskatchewan - Crop yields", 
       y = "Tonnes / Hectare", x = NULL, caption = myCaption)
ggsave("crops_saskatchewan_08.png", mp, width = 6, height = 5)

Per Person

# Prep data
pp <- agData_STATCAN_Population %>% 
  filter(Month == 1, Area == "Saskatchewan", Year == 2020) %>%
  pull(Value)
myCrops <- cropList(measurement = "Production", years = 2020)
xx <- d1 %>% 
  filter(Year == 2020, Item %in% myCrops,
         Measurement == "Production") %>%
  mutate(Item = factor(Item, levels = myCrops),
         PerPerson = Value / pp) %>%
  filter(PerPerson > 0.1)
# Plot
mp <- ggplot(xx, aes(x = Item, y = PerPerson, fill = Item)) + 
  geom_col(color = "Black", alpha = 0.7) + 
  geom_label(aes(label = round(PerPerson,1)), vjust = -0.15, fill = "White",
             size = 3, label.padding = unit(0.15, "lines")) +
  facet_grid(Year~.) + 
  scale_y_continuous(limits = c(0,15), expand = c(0,0)) +
  scale_fill_manual(values = agData_Colors) +
  theme_agData(legend.position = "none", 
               axis.text.x = element_text(angle = 45, hjust = 1)) + 
  labs(title = "Saskatchewan - Crop Production Per Person", 
       y = "1000 kg", x = NULL, caption = myCaption)
ggsave("crops_saskatchewan_09.png", mp, width = 6, height = 4)

All Crops

Area Seeded

# Prep data
xx <- d1 %>% filter(Measurement == "Area Seeded") 
myCrops <- unique(c(cropList(measurement = "Area Seeded", years = 2017), 
                    as.character(xx$Item)))
xx <- xx %>% mutate(Item = factor(Item, levels = myCrops))
# Plot
mp <- ggplot(xx, aes(x = Year, y = Value / 1000000, color = Item)) + 
  geom_line(alpha = 0.7) + 
  facet_wrap(Item ~ ., ncol = 6) + 
  scale_color_manual(values = agData_Colors) +
  theme_agData(legend.position = "none", 
               axis.text.x = element_text(angle = 45, hjust = 1)) + 
  labs(title = "Saskatchewan Crops - Area Seeded", 
       y = "Million Hectares", x = NULL, caption = myCaption)
ggsave("crops_saskatchewan_10.png", mp, width = 6, height = 5)

Production

# Prep data
xx <- d1 %>% filter(Measurement == "Production") 
myCrops <- unique(c(cropList(measurement = "Production", years = 2017), 
                    as.character(xx$Item)))
xx <- xx %>% mutate(Item = factor(Item, levels = myCrops))
# Plot
mp <- ggplot(xx, aes(x = Year, y = Value / 1000000, color = Item)) + 
  geom_line(alpha = 0.7) + 
  facet_wrap(Item ~ ., ncol = 6) + 
  scale_color_manual(values = agData_Colors) +
  theme_agData(legend.position = "none", 
               axis.text.x = element_text(angle = 45, hjust = 1)) + 
  labs(title = "Saskatchewan Crops - Production", 
       y = "Million Hectares", x = NULL, caption = myCaption)
ggsave("crops_saskatchewan_11.png", mp, width = 6, height = 5)

Treemap

# Prep data
xx <- d1 %>% filter(Year == 2020, Measurement == "Area Seeded") %>%
  arrange(desc(Value)) %>%
  mutate(Item = factor(Item, levels = unique(.$Item)))
# Plot
mp <- ggplot(xx, aes(area = Value, fill = Item, label = Item)) +
  geom_treemap(color = "black", alpha = 0.7, size = 1.5) +
  geom_treemap_text(place = "centre", grow = T, color = "white") +
  scale_fill_manual(values = agData_Colors) +
  theme_agData(legend.position = "none") +
  labs(title = "Saskatchewan Cropland", 
       subtitle = "Area Seeded 2020", caption = myCaption)
ggsave("crops_saskatchewan_12.png", mp, width = 6, height = 4)

Animation

# Prep data
xx <- d1 %>% filter(Measurement == "Area Seeded") %>%
  arrange(desc(Year), desc(Value)) %>% 
  mutate(Item = factor(Item, levels = unique(.$Item)))
# Plot
mp <- ggplot(xx, aes(area = Value, fill = Item, label = Item)) +
  geom_treemap(layout = "fixed", color = "black", alpha = 0.7, size = 1.5) +
  geom_treemap_text(layout = "fixed", place = "centre", 
                    grow = T, color = "white") +
  scale_fill_manual(values = agData_Colors) +
  theme_agData(legend.position = "none") +
  labs(title = "Saskatchewan Cropland - Area Seeded",
       subtitle = "Year: {frame_time}", caption = myCaption) +
  transition_time(Year)
anim_save("crops_saskatchewan_gif_03.gif", mp,
          nframes = 600, fps = 20, end_pause = 60, 
          width = 900, height = 600, res = 150)

Farm Area

# Prep data
xx <- d2 %>%
  filter(Item == "Total area of farms", 
         Unit == "Hectares", !is.na(Value))
# Plot
mp <- ggplot(xx, aes(x = Year, y = Value / 1000000)) + 
  geom_col(alpha = 0) +
  geom_line(color = "darkgreen", size = 1.5, alpha = 0.7) +
  scale_x_continuous(breaks = seq(1920, 2020, 10)) +
  scale_y_continuous(breaks = seq(0, 30, 5)) +
  theme_agData() +
  labs(title = "Saskatchewan - Total Farmland Area", 
       y = "Million Hectares", x = NULL, caption = myCaption)
ggsave("crops_saskatchewan_13.png", mp, width = 6, height = 4)

Summerfallow

# Prep data
myColors <- c("darkgreen","darkgoldenrod2","darkred")
myCrops <- c("Summerfallow", "Wheat", "Canola")
xx <- d1 %>% filter(Measurement == "Area Seeded", Item %in% myCrops) %>%
  mutate(Item = factor(Item, levels = myCrops))
# Plot
mp <- ggplot(xx, aes(x = Year, y = Value / 1000000, 
                     color = Item, alpha = Item, size = Item)) + 
  geom_line() +
  scale_color_manual(name = NULL, values = myColors) +
  scale_alpha_manual(name = NULL, values = c(0.8,0.6,0.6)) +
  scale_size_manual(name = NULL, values = c(1.75,1.5,1.5)) +
  scale_x_continuous(breaks = seq(1910, 2020, 10)) +
  theme_agData(legend.position = "bottom") +
  labs(title = "Saskatchewan - Summerfallow", 
       y = "Million Hectares", x = NULL, caption = myCaption)
ggsave("crops_saskatchewan_14.png", mp, width = 6, height = 4)

1960 Crop Area

# Prep data
myYears <- c(2020, 1990, 1960)
myCrops <- cropList(measurement = "Area Seeded", years = myYears)[1:9]
xx <- d1 %>% filter(Year %in% myYears, Measurement == "Area Seeded")
x1 <- xx %>% filter(Item %in% myCrops)
x2 <- xx %>% filter(!Item %in% myCrops) %>% 
  group_by(Area, Year, Measurement, Unit) %>%
  summarise(Value = sum(Value)) %>%
  mutate(Item = "Other")
myCrops <- c(myCrops[myCrops != "Summerfallow"], "Other", "Summerfallow")
xx <- bind_rows(x1, x2) %>%
  mutate(Item = factor(Item, levels = myCrops))
# Plot
mp <- ggplot(xx, aes(x = "", y = Value / 1000000, fill = Item)) + 
  geom_col(color = "black", alpha = 0.7) +
  facet_grid(. ~ Year) +
  scale_fill_manual(name = NULL, values = agData_Colors) +
  theme_agData() +
  labs(title = "Saskatchewan - Area Seeded", 
       y = "Million Hectares", x = NULL, caption = myCaption)
ggsave("crops_saskatchewan_15.png", mp, width = 6, height = 4)

Activist Graph

# Prep data
myColors <- c("darkgoldenrod2","darkgreen","darkred")
x1 <- d1 %>% 
  filter(Measurement == "Production",
         Item %in% c("Lentils", "Peas", "Beans", "Chickpeas")) %>%
  group_by(Year) %>% 
  summarise(Value = sum(Value)) %>%
  mutate(Item = "Fake Meat Proteins (Legumes)")
x2 <- agData_STATCAN_Crops %>% 
  filter(Area == "Saskatchewan", Measurement == "Production",
         Item %in% c("Canola", "Wheat")) %>%
  mutate(Item = plyr::mapvalues(Item, c("Canola", "Wheat"), 
                                      c("Evil GMO Oilseeds (Canola)", "Toxic Gluten (Wheat)")))
xx <- bind_rows(x1, x2) %>% filter(Year < 2021) %>%
  mutate(Item = factor(Item, levels = c("Toxic Gluten (Wheat)", "Fake Meat Proteins (Legumes)", 
                                        "Evil GMO Oilseeds (Canola)")))
# Plot
mp <- ggplot(xx, aes(x = Year, y = Value / 1000000, color = Item)) +
  geom_line(size = 1.5, alpha = 0.7) +
  scale_color_manual(name = NULL, values = myColors) +
  scale_x_continuous(breaks = seq(1910, 2020, 10)) +
  theme_agData(legend.position = "bottom") +
  labs(title = "Saskatchewan's Industrialized Food Production", 
       y = "Million Tonnes", x = NULL, caption = myCaption)
ggsave("crops_saskatchewan_16.png", mp, width = 6.5, height = 4)

© Derek Michael Wright