Visualizing changes over time of the prevalence of undernourishment

Using {ggplot2} to create a line plot for the evolution of food security in the world

data visualization
food security
ggthemr
ggplot2
line chart
Author

Juan Armando Torres Munguía

Published

April 18, 2025

About the data

Set-up

Loading data from FAO

food_security <- read.csv("FAOSTAT_data_en_4-27-2025.csv")

Data wrangling

undernourishment <- food_security |>
  filter(Item == "Prevalence of undernourishment (percent) (3-year average)") |>
  filter(Element == "Value") |>
  filter(Area %in% c("Central America", "Caribbean", "South America", 
                     "Northern Africa (excluding Sudan)", "Sub-Saharan Africa (including Sudan)", 
                     "Central Asia", "Southern Asia", "South-eastern Asia")) |>
  mutate(
    Area = fct_recode(Area,
                      `Northern Africa` = "Northern Africa (excluding Sudan)", 
                      `Sub-Saharan Africa` = "Sub-Saharan Africa (including Sudan)"),
    Value = as.numeric(Value)/100,
    Year = fct_recode(Year, 
                      `2001` = "2000-2002", `2002` = "2001-2003", `2003` = "2002-2004", `2004` = "2003-2005", `2005` = "2004-2006",
                      `2006` = "2005-2007", `2007` = "2006-2008", `2008` = "2007-2009", `2009` = "2008-2010", `2010` = "2009-2011", 
                      `2011` = "2010-2012", `2012` = "2011-2013", `2013` = "2012-2014", `2014` = "2013-2015", `2015` = "2014-2016", 
                      `2016` = "2015-2017", `2017` = "2016-2018", `2018` = "2017-2019", `2019` = "2018-2020", `2020` = "2019-2021",
                      `2021` = "2020-2022", `2022` = "2021-2023"),
    Year = as.numeric(as.character(Year))
    )

Set theme settings and define fonts, colors, and text to be used in the waffle chart

 my_theme <- function() { 
   
   theme_minimal(
    base_family = "fjalla"
    ) + 
  
  # Custom format
  theme(
    # Title setting
    plot.title = element_text(
      color = "black",
      size = 18
    ), 
    plot.title.position = "plot", 
    
    # Subtitle setting
    plot.subtitle = element_text(
      color = "grey50",
      size = 14
    ), 
    
    # Axis settings
    axis.title = element_text(
      color = "black",
      size = 11
    ),
    
    axis.text = element_text(
      color = "grey50",
      size = 11
    ),
    
    axis.ticks = element_line(
      size = 1.25, 
      color = "black"
      ),
    
    axis.line.x.bottom = element_line(
      color = "black",
      size = 1.25
      ),
    
    axis.line.y.left = element_line(
      color = "black",
      size = 1.25
      ),
    
    # Panel
    panel.grid = element_blank(),
    
    # Caption settings
    plot.caption.position = "plot", 
    plot.caption = element_markdown(
      size = 10,
      hjust = 0
      ),
    
    # Background
    plot.background = element_rect(
      color = "#FFF5EB",
      fill = "#FFF5EB"
      )
    )
 }

Create the line chart

# Plot
font_add_google("Fjalla One", "fjalla")

showtext_auto()

ggplot(undernourishment) +
  geom_line(
    linewidth = 1.5,
    aes(x = Year,
        y = Value,
        color = Area, 
        group = Area)
  ) + 
  
  scale_color_manual(values = c("#B2432F", "#DB735C", 
                                "#919C4C", "#9B5672",
                                "#B58900", "#3A6589",
                                "#6F5438", "#828585")) + 
  
  scale_y_continuous(
    labels = scales::label_percent()
    ) +
  
  scale_x_continuous(
    expand = expansion(add = 0.8),
    breaks = 2001:2022
  ) + 
  
  geom_textpath(
    text_only = TRUE,
    spacing =  50,
    data = filter(undernourishment,
                  Area %in% c("Sub-Saharan Africa", "Caribbean", 
                              "Southern Asia", "Central Asia")
    ),
    aes(x = Year,
        y = Value,
        color = Area,
        label = Area), 
    vjust = -0.5, 
    hjust = 1, 
    size = 3) +
  
  geom_textpath(
    text_only = TRUE,
    spacing =  50,
    data = filter(undernourishment,
                  Area %in% c("South America", "Central America", 
                              "Northern Africa")
    ),
    aes(x = Year,
        y = Value,
        color = Area,
        label = Area), 
    vjust = -0.5, 
    hjust = 0, 
    size = 3) +
  
  geom_textpath(
    text_only = TRUE,
    spacing =  50,
    data = filter(undernourishment,
                  Area == "South-eastern Asia"
    ),
    aes(x = Year,
        y = Value,
        color = Area,
        label = Area), 
    vjust = -0.5, 
    hjust = 0.5, 
    size = 3) +
  
  guides(color = "none") +
  
  labs(
    title = "Prevalence of undernourishment by region | 2001-2022",
    subtitle = "Proportion of the population with a dietary energy consumption below the minimum required for maintaining a healthy life and carrying out a light physical activity",
    caption = paste0(
      "<span style='color:black;'>Source:</span> <span style='color:grey50;'>FAO Statistics Division</span>",
      "<br>",
      "<span style='color:black;'>Plot:</span> <span style='color:grey50;'>Juan Torres Munguía</span>"
    ),
    x = "",
    y = ""
  ) + 
  my_theme()

Save the line chart as an image

showtext_opts(dpi = 320)  
ggsave(
  "undernourishment.png",
  dpi = 320,
  width = 14,
  height = 7,
  units = "in"
)

Citation

BibTeX citation:
@online{torres munguía2025,
  author = {Torres Munguía, Juan Armando},
  title = {Visualizing Changes over Time of the Prevalence of
    Undernourishment},
  date = {2025-04-18},
  langid = {en}
}
For attribution, please cite this work as:
Torres Munguía, Juan Armando. 2025. “Visualizing Changes over Time of the Prevalence of Undernourishment.” April 18, 2025.