Plotting global rice production using FAO data: 1961–2021
Rice is one of the most important staple crops worldwide, and analyzing its production trends can provide valuable insights for policymakers, researchers, and agricultural stakeholders.
In this post, we will explore how to plot global rice production using data from the Food and Agriculture Organization (FAO): https://www.fao.org/faostat/en/#data/QCL
The data underwent some wrangling to extract Continent data based on the corresponding countries as shown on an earlier post. The cleaned data is available here.
Let’s now have a glimpse of the data:
> headtail(df)
country year value Continent incGroup
1 Afghanistan 2011 210000 Asia LIC
2 Afghanistan 2016 119000 Asia LIC
3 Afghanistan 2014 220000 Asia LIC
4 Afghanistan 1971 2e+05 Asia LIC
... <NA> ... ... <NA> <NA>
7316 Zimbabwe 2018 3371 Africa LMIC
7317 Zimbabwe 2019 2529 Africa LMIC
7318 Zimbabwe 2020 1260 Africa LMIC
7319 Zimbabwe 2021 3466 Africa LMIC
Now it’s time to bring ggplot
to the picture. We will plot the volume of production across the years by continent:
df %>%
drop_na() %>%
group_by(Continent, year) %>%
summarize(value = mean(value)) %>%
ggplot(aes(x=year, y=value, color=Continent)) +
geom_line() +
theme(axis.text.x = element_text(angle = 90, hjust = 1) ,
axis.title = element_text(size = 16),
axis.text = element_text(size = 12),
plot.title = element_text(size = 20, face = "bold")
) +
scale_x_continuous(breaks = seq(min(df$year), max(df$year), by = 5))
And then by income groups (WB classification):
df %>%
drop_na() %>%
group_by(incGroup, year) %>%
summarize(value = mean(value)) %>%
ggplot(aes(x=year, y=value, color=incGroup)) +
geom_line() +
theme(axis.text.x = element_text(angle = 90, hjust = 1) ,
axis.title = element_text(size = 16),
axis.text = element_text(size = 12),
plot.title = element_text(size = 20, face = "bold")
) +
scale_x_continuous(breaks = seq(min(df$year), max(df$year), by = 5))
Of course, we can stratify the plot both by continent and income groups:
df %>%
drop_na() %>%
group_by(Continent, incGroup, year) %>%
summarize(value = mean(value)) %>
ggplot(aes(x=year, y=value, color=Continent)) +
geom_line() +
scale_x_continuous(breaks = seq(min(df$year), max(df$year), by = 5)) +
facet_wrap(~incGroup) +
theme(
axis.title = element_text(size = 16),
axis.text = element_text(size = 12),
axis.text.x = element_text(angle = 90, hjust = 1),
plot.title = element_text(size = 20, face = "bold")
)
Happy ggplotting!