'How to add labels to plot with facets? [duplicate]

I'm working with a data frame like this:

food_totals <- tibble::tribble(
  ~ food, ~ year, ~ total, ~ overall_change,
  "Orange", 2012, 5, -3,
  "Orange", 2013, 3, -3,
  "Orange", 2014, 2, -3,
  "Kiwi", 2012, 4, 2,
  "Kiwi", 2013, 5, 2,
  "Kiwi", 2014, 6, 2,
  "Eggplant", 2012, 4, -4,
  "Eggplant", 2013, 2, -4,
  "Eggplant", 2014, 0, -4
)

I want to create a set of line charts to show the change over time for each, which is easy enough.

food_totals %>% 
           ggplot(aes(year, total)) + 
  geom_line(aes(colour = food, group = food)) + 
  facet_wrap(vars(food)) + 
  theme(axis.text.x = element_text(angle = 90))

The problem I'm having is that I want to include an annotation on each of the charts that shows the value in that food's "overall_change" column. I'd like the annotation to be a label on the top center of the chart itself. Whenever I try to insert overall_change as a label, I run into errors.

Thank you for your time!

r


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source