1

I can't for the life of me figure out what's going on here. Here's the code:

full_c_df |>
  ggplot() +
  aes(
    x = year_month,
    y = conversions,
    fill = series
    
  ) +
  geom_bar(stat = "identity", position = "dodge") +
  geom_text_repel(
    aes(label = round(conversions, digits = 0)),
    family = "barlow",
    angle = 45,
    position = position_dodge(1),
    stat = "identity", box.padding = 1
  ) +
  labs(
    title = "Estimated Traffic to Bottom of XXX, 2022 Actuals and Forecast",
    caption = paste0(
      "Data sourced from XXX Excludes XXX traffic. Attribution type is ",
      attribution,
      " touch. Last date of actual data is ",
      last_date,
      "."
    ),
    x = "Month of Year",
    y = "conversions",
    subtitle = paste0("Analysis by TrustInsights.ai for week of ", today, ".")
  ) +
  scale_fill_manual(values = c("palegreen4", "tomato3", "lightblue")) +
  annotation_custom(rast) +
  theme_light(base_size = 14, base_family = "barlow")

And here's what it generates.

enter image description here

The goal is to get each label centered on the appropriate bar. What am I doing wrong? I've been unable to get this right either with stock geom_text or with ggrepel's geom_text_repel.

Christopher Penn
  • 539
  • 4
  • 14
  • 1
    My first guess was also that this is related to the `group` aes as suggested by Allan. But after a closer look at your plot I would guess that your `year_month` column is a `Date` and that this is the reason for the issue. As you display data by months in that case a possible fix would be to convert your `year_month` variable to a character. But as Allan said, without any data we can only guess. – stefan Oct 04 '22 at 14:19
  • 1
    Boom, that was it. a mutate to character on year_month fixed it. Thank you! – Christopher Penn Oct 04 '22 at 14:43

1 Answers1

0

The solution per Stefan and Allan was to convert the date to a character vector instead.

Christopher Penn
  • 539
  • 4
  • 14