USA Maize Production
Graphs of maize production in the USA using USDA data
Data
Prepare Data
# devtools::install_github("derekmichaelwright/agData")
library(agData)
library(gganimate)
# Prep data
= "www.dblogr.com/ or derekmichaelwright.github.io/dblogr/ | Data: USDA"
myCaption1 = "www.dblogr.com/ or derekmichaelwright.github.io/dblogr/ | Data: USDA & NCGA"
myCaption2 = "www.dblogr.com/ or derekmichaelwright.github.io/dblogr/ | Data: USDA & FAOSTAT"
myCaption3 #
<- c("darkcyan", "darkorange", "darkgreen", "darkred")
myColors <- c("Open-Pollination", "Hybrid", "Biotech", "Yield Contest")
mylevels <- agData_USDA_Grains %>%
d1 filter(Item == "Maize") %>%
mutate(Era = ifelse(Year < 1937, mylevels[1],
ifelse(Year < 1996, mylevels[2], mylevels[3])),
Era = factor(Era, levels = mylevels))
<- agData_MaizeContest
d2 #
<- c("darkblue", "darkred", "darkgoldenrod2", "darkgreen")
myColors_Areas <- agData_FAO_Crops %>%
d3 filter(Item == "Maize (corn)", Measurement == "Yield",
%in% c("Germany", "Mexico", "Africa")) Area
Heterosis
# Prep Data
<- d1 %>% filter(Measurement == "Yield")
xx # Calculate slopes
<- xx %>% filter(Era == mylevels[1])
c1 <- xx %>% filter(Era == mylevels[2])
c2 <- xx %>% filter(Era == mylevels[3])
c3 <- round(summary(lm(data = c1, Value ~ Year))$coefficients[2] / 1000, 3)
c1 <- round(summary(lm(data = c2, Value ~ Year))$coefficients[2] / 1000, 3)
c2 <- round(summary(lm(data = c3, Value ~ Year))$coefficients[2] / 1000, 3)
c3 # Plot Yields
<- ggplot(xx, aes(x = Year, y = Value / 1000, color = Era)) +
mp geom_line(size = 1, alpha = 0.5, color = "black") +
geom_line(size = 1.5, alpha = 0.7) +
scale_color_manual(name = "Breeding Era:", values = myColors) +
scale_x_continuous(breaks = seq(1865, 2015, 10), minor_breaks = NULL) +
scale_y_continuous(breaks = seq(0, 12, 2)) +
coord_cartesian(xlim = c(1865, 2018), ylim = c(0, 11.5), expand = F) +
theme_agData(legend.position = "bottom",
axis.text.x = element_text(angle = 45, hjust = 1)) +
labs(title = "USA - Maize Yields", x = NULL,
y = "Tonnes / Hectare", caption = myCaption1)
<- mp +
mp1 stat_smooth(aes(x = Year, y = Value / 1000, group = Era),
geom = "line", method = "lm", se = F,
color = "black", alpha = 0.6) +
annotate("text", x = 1900, y = 2.75, size = 4, label = paste("m =", c1)) +
annotate("text", x = 1965, y = 6.5, size = 4, label = paste("m =", c2)) +
annotate("text", x = 2000, y = 11, size = 4, label = paste("m =", c3))
ggsave("maize_usa_01.png", mp1, width = 6, height = 4)
# Animate
<- mp +
mp transition_reveal(Year) +
view_follow(fixed_y = T, fixed_x = c(1865, NA))
anim_save("maize_usa_gif_01.gif", mp,
nframes = 300, fps = 20, end_pause = 60,
width = 900, height = 600, res = 150)
Maize Potential
# Prep data
<- d2 %>%
x2 filter(Unit == "kg/ha") %>%
mutate(Era = "Yield Contest",
Measurement = "Yield") %>%
group_by(Era, Measurement, Year) %>%
summarise(Value = mean(Value))
<- bind_rows(d1, x2) %>%
xx filter(Measurement == "Yield") %>%
mutate(Era = factor(Era, levels = mylevels))
# Plot
<- ggplot(xx, aes(x = Year, y = Value / 1000, color = Era)) +
mp geom_line(size = 1.5, alpha = 0.7) +
scale_color_manual(name = "Breeding Era:", values = myColors) +
scale_x_continuous(breaks = seq(1865, 2015, 10), minor_breaks = NULL) +
coord_cartesian(xlim = c(1865, 2019), ylim = c(0, 27), expand = F) +
theme_agData(legend.position = "bottom",
axis.text.x = element_text(angle = 45, hjust = 1),
legend.text=element_text(size = 7)) +
labs(title = "USA - Maize Yields", x = NULL,
y = "Tonnes / Hectare", caption = myCaption2)
ggsave("maize_usa_02.png", mp, width = 6, height = 4)
Area vs Production
# Prep Data
<- c("Area Harvested (Hectares)", "Production (Tonnes)")
myLabels <- d1 %>% filter(Measurement %in% c("Area Harvested", "Production"))
xx # Plot Production
<- ggplot(xx) +
mp geom_line(aes(x = Year, y = Value / 1000000, color = Measurement),
size = 1.5, alpha = 0.7) +
scale_color_manual(name = NULL, values = myColors, labels = myLabels) +
scale_x_continuous(breaks = seq(1865, 2015, 10), minor_breaks = NULL) +
coord_cartesian(xlim = c(1865, 2018), ylim = c(0,400), expand = 0) +
theme_agData(legend.position = "bottom",
axis.text.x = element_text(angle = 45, hjust = 1)) +
labs(title = "USA - Maize Production", x = NULL,
y = "Million", caption = myCaption1)
ggsave("maize_usa_03.png", mp, width = 6, height = 4)
Developed vs Developing Countries
# Prep Data
<- bind_rows(d1, d3) %>%
xx filter(Measurement == "Yield") %>%
mutate(Area = factor(Area, levels = c("USA", "Germany", "Mexico", "Africa")))
# Plot
<- ggplot(xx, aes(x = Year, y = Value / 1000, color = Area)) +
mp geom_line(size = 1.25, alpha = 0.7) +
scale_color_manual(name = NULL, values = myColors_Areas) +
scale_x_continuous(breaks = seq(1865, 2015, 10), minor_breaks = NULL) +
scale_y_continuous(breaks = seq(0, 12, 2)) +
theme_agData(legend.position = "bottom",
axis.text.x = element_text(angle = 45, hjust = 1)) +
labs(title = "Maize Yields - Developed vs Developing Countries",
y = "Tonnes / Hectare", x = NULL, caption = myCaption3)
ggsave("maize_usa_04.png", mp, width = 6, height = 4)
Maize Contest
# Prep data
<- d1 %>% filter(Measurement == "Yield", Year >= 2010) %>%
x1 mutate(Measurement = "Commercial Average")
<- d2 %>% filter(Unit == "kg/ha")
x2 #
<- bind_rows(x1, x2) %>%
xx arrange(desc(Value)) %>%
mutate(Measurement = factor(Measurement, levels = unique(Measurement)))
# Plot
<- ggplot(xx, aes(x = Year, y = Value / 1000, color = Measurement)) +
mp geom_line(size = 1.5, alpha = 0.7) +
scale_color_manual(name = NULL, values = agData_Colors) +
theme_agData() +
labs(title = "USA - Maize Yield Contests", x = NULL,
y = "Tonnes / Hectare", caption = myCaption2)
ggsave("maize_usa_05.png", mp, width = 7, height = 4)
Average vs Max Yield
# Prep data
<- d1 %>%
x1 filter(Year > 1990, Measurement == "Yield") %>%
mutate(Measurement = "Average Yield")
<- d2 %>% filter(Unit == "kg/ha") %>%
x2 group_by(Year) %>% summarise(Value = max(Value)) %>%
mutate(Measurement = "Max Yield", Value = Value)
#
<- bind_rows(x1, x2)
xx # Plot
<- ggplot(xx, aes(x = Year, y = Value / 1000, color = Measurement)) +
mp geom_line(size = 1.5, alpha = 0.7) +
scale_x_continuous(breaks = seq(1990, 2020, by = 5)) +
scale_color_manual(name = NULL, values = c("darkgreen", "darkred")) +
theme_agData(legend.position = "bottom") +
labs(title = "USA - Max vs. Average Maize Yields",
y = "Tonnes / Hectare", x = NULL, caption = myCaption2)
ggsave("maize_usa_06.png", mp, width = 6, height = 4)
Hectares per tonne
# Prep data
<- d1 %>%
xx filter(Measurement == "Yield") %>%
mutate(Value = 1000 / Value)
# Plot
<- ggplot(xx, aes(x = Year, y = Value)) +
mp geom_col(color = "black", fill = "darkgreen", alpha = 0.7, lwd = 0.3) +
scale_x_continuous(breaks = seq(1865, 2015, 10), minor_breaks = NULL) +
scale_y_continuous(breaks = seq(0, 1, 0.1)) +
theme_agData(axis.text.x = element_text(angle = 45, hjust = 1)) +
labs(title = "USA - Hectares Needed To Produce 1 Tonne of Maize",
y = NULL, x = NULL, caption = myCaption1)
ggsave("maize_usa_07.png", mp, width = 6, height = 4)
# Prep data
<- xx %>% filter(Year %in% seq(1875, 2015, by = 10))
xx # Plot
<- ggplot(xx, aes(x = Year, y = Value)) +
mp geom_col(color = "black", fill = "darkgreen", alpha = 0.7) +
scale_x_continuous(breaks = seq(1875, 2015, 10), minor_breaks = NULL) +
scale_y_continuous(breaks = seq(0, 1, 0.1)) +
theme_agData(axis.text.x = element_text(angle = 45, hjust = 1)) +
labs(title = "USA - Hectares Needed To Produce 1 Tonne of Maize",
y = NULL, x = NULL, caption = myCaption1)
ggsave("maize_usa_08.png", mp, width = 6, height = 4)
Yield Gains
# Prep data
<- d1 %>% filter(Year >= 1940)
xx <- xx %>% filter(Year == 1940, Measurement == "Yield") %>% pull(Value)
yy <- xx %>% filter(Measurement == "Area Harvested") %>%
x1 mutate(Value = Value * yy / 1000,
Measurement = "1940 Yields")
<- xx %>% filter(Measurement == "Production") %>%
xx mutate(Measurement = "Actual Yields") %>%
bind_rows(x1)
# Plot
<- ggplot(xx, aes(x = Year, y = Value / 1000000, color = Measurement)) +
mp geom_line(size = 1.5, alpha = 0.7) +
scale_color_manual(name = NULL, values = c("darkred", "darkgreen")) +
scale_x_continuous(breaks = seq(1940, 2020, 10)) +
theme_agData(legend.position = "bottom") +
labs(title = "USA - Maize Production",
subtitle = "Based on Actual Yields vs. 1940 Yields",
y = "Million Tonnes", x = NULL, caption = myCaption1)
ggsave("maize_usa_09.png", mp, width = 6, height = 4)
Addition Production
# Prep data
<- xx %>% select(-Unit) %>%
xx spread(Measurement, Value) %>%
mutate(Difference = `Actual Yields` - `1940 Yields`)
# Plot
<- ggplot(xx, aes(x = Year, y = Difference / 1000000)) +
mp geom_bar(stat = "identity",fill = "darkgreen", alpha = 0.7,
color = "black", lwd = 0.3) +
scale_x_continuous(breaks = seq(1940, 2020, 10)) +
theme_agData() +
labs(title = "USA - Additional Maize Production Based on Yield Gains After 1940",
y = "Million Tonnes", x = NULL, caption = myCaption1)
ggsave("maize_usa_10.png", mp, width = 7, height = 4)
Yield Increases
# Prep data
<- agData_USDA_Grains %>% arrange(Year) %>%
xx filter(Measurement == "Yield", Item == "Maize")
<- mean(xx %>% filter(Year <= 1935) %>% pull(Value))
xb # Calculate yield gains compared to 1935
$YieldGains <- NA
xxfor(i in 6:nrow(xx)) {
$YieldGains[i] <- 100 * (xx$Value[i] - mean(xx$Value[(i-1):(i-6)])) / xb
xx
}#
<- paste("Percent Yield Gain = 100 * (Yi - Y5) / Yb",
myCaption4 "Current years yield = Yi",
"Average yield for previous 5 years = Y5",
"Average yield from 1866 - 1935 = Yb\n",
sep = "\n")
myCaption1, # Plot
<- ggplot(xx, aes(x = Year, y = YieldGains)) +
mp geom_hline(yintercept = 0) +
geom_col(fill = "darkgreen", alpha = 0.4) +
stat_smooth(geom = "line", method = "loess", se = F) +
scale_x_continuous(breaks = seq(1860, 2020, 20)) +
scale_y_continuous(breaks = seq(-110, 110, 20),
sec.axis = sec_axis(~ ., breaks = seq(-110, 110, 20))) +
theme_agData() +
labs(title = "USA - US Yearly Maize Yield Gains",
y = "Percent Yield Gain", x = NULL, caption = myCaption4)
ggsave("maize_usa_11.png", mp, width = 6, height = 4)
# Prep Data
<- c("darkcyan", "darkorange", "darkgreen")
myColors <- c("Open-Pollination", "Hybrid", "Biotech")
mylevels <- agData_USDA_Grains %>%
xx filter(Item == "Maize") %>%
mutate(Era = ifelse(Year < 1937, mylevels[1],
ifelse(Year < 1996, mylevels[2], mylevels[3])),
Era = factor(Era, levels = mylevels))
<- xx %>% filter(Measurement == "Yield")
x1 # Calculate slopes
<- x1 %>% filter(Era == mylevels[1])
c1 <- x1 %>% filter(Era == mylevels[2])
c2 <- x1 %>% filter(Era == mylevels[3])
c3 <- round(summary(lm(data = c1, Value ~ Year))$coefficients[2] / 1000, 3)
c1 <- round(summary(lm(data = c2, Value ~ Year))$coefficients[2] / 1000, 3)
c2 <- round(summary(lm(data = c3, Value ~ Year))$coefficients[2] / 1000, 3)
c3 # Plot Yields
<- ggplot(x1, aes(x = Year, y = Value / 1000, color = Era)) +
mp geom_line(size = 1, alpha = 0.5, color = "black") +
geom_line(size = 1.5, alpha = 0.7) +
scale_color_manual(name = "Breeding Era:", values = myColors) +
scale_fill_manual(name = "Breeding Era:", values = myColors) +
scale_x_continuous(breaks = seq(1865, 2015, 10), minor_breaks = NULL) +
scale_y_continuous(breaks = seq(0, 12, 2)) +
coord_cartesian(xlim = c(1865, 2018), ylim = c(0, 11.5), expand = F) +
theme_agData(legend.position = "bottom",
axis.text.x = element_text(angle = 45, hjust = 1)) +
labs(title = "Maize Yields in the United States",
y = "Tonnes / Hectare", x = NULL, caption = myCaption1)
<- mp +
mp1 stat_smooth(aes(x = Year, y = Value / 1000, group = Era),
geom = "line", method = "lm", se = F,
color = "black", alpha = 0.6) +
annotate("text", x = 1900, y = 2.75, size = 4, label = paste("m =", c1)) +
annotate("text", x = 1965, y = 6.5, size = 4, label = paste("m =", c2)) +
annotate("text", x = 2005, y = 11, size = 4, label = paste("m =", c3))
ggsave("maize_usa_01.png", mp1, width = 6, height = 4)