ggplot2 – How To Update R Values

I have the below code which runs a 3 month picture of my metrics. I open the saved code, remove "Nov-21" and add "Feb-22", then delete the first entry for each metric and add "Feb-22" entry to end of each metric (957L, 1208L, 1054L, 476L). Previously, the 3 month picture was Nov, Dec, Jan but when I update the metric values to show Dec, Jan, Feb my plot updates but the value labels above the bar still show Nov, Dec, Jan values:

library(ggplot2)
library(dplyr)
library(tidyr)

data <- structure(list(Month = c("Dec-21", "Jan-22", "Feb-22"), 
                       `Metric 1` = c(640L, 795L, 957L), 
                       `Metric 2` = c(1438L, 939L, 1208L), 
                       `Metric 3` = c(1544L, 1000L, 1054L), 
                       `Metric 4` = c(740L, 297L, 476L)), 
                  class = "data.frame", row.names = c(NA, -3L))

data %>% 
  pivot_longer(-1) %>%
  mutate(Month = factor(Month, c("Dec-21", "Jan-22", "Feb-22")),
         name = stringr::str_wrap(name, 12),
         name = factor(name, levels(factor(name))[c(2, 1, 4, 3)])) %>%
  ggplot(aes(name, value, fill = Month)) +
  geom_col(width = 0.6, position = position_dodge(width = 0.8)) +
  geom_text(aes(label=Values), position=position_dodge(width=0.9), vjust=-0.25) +
  scale_fill_manual(values = c("red", "orange", "purple")) +
  scale_y_continuous(breaks = 0:9 * 200) +
  labs(x = "", y = "", title = "Title", subtitle = "3 Month View") +
  theme_bw() +
  theme(panel.grid.major.x = element_blank(),
        panel.border = element_blank(),
        plot.title = element_text(hjust = 0))

This code produces the below visual:
enter image description here

As you can see, the bars show the correct height value but the first value label is incorrect and still shows Nov-Jan values instead of updated Dec-Feb. What do I need to do to update my value so the labels shows the correct 3 month period?

Read more here: Source link