0

I'm trying to adjust each individual x-axis label by adding an annotation.

I'm able to adjust the first two labels, but the next 6 just repeat those first two, instead of taking on their own individual labels (the numbers should be different).

Here's the scale_x_discrete part of my ggplot script:

 scale_x_discrete(
    
    # Change x group labels
    labels = c(
      paste0("PPA\n(", comma(PPA_LA_2019, digits = 0), "\ntotal)"), 
      paste0("Non-PPA\n(", comma(non_PPA_LA_2019, digits = 0), "\ntotal)"),
      paste0("PPA\n(", comma(PPA_LA_2020, digits = 0), "\ntotal)"), 
      paste0("Non-PPA\n(", comma(non_PPA_LA_2020, digits = 0), "\ntotal)"),
      paste0("PPA\n(", comma(PPA_LA_2021, digits = 0), "\ntotal)"), 
      paste0("Non-PPA\n(", comma(non_PPA_LA_2021, digits = 0), "\ntotal)"),
      paste0("PPA\n(", comma(PPA_LA_2022, digits = 0), "\ntotal)"), 
      paste0("Non-PPA\n(", comma(non_PPA_LA_2022, digits = 0), "\ntotal)")
      )
  ) +

Here are the values I want to be showing up across the x-axis: x-axis label values

And here's what I'm getting: current x-axis

stefan
  • 90,330
  • 6
  • 25
  • 51
  • 5
    That will not work. As your axis has only two breaks per panel only the first two labels will be used. Instead try with mapping `paste0(prior_status, "\n(", comma(n, digits = 0), "\ntotal)")` on `x` and use `scales="free_x"` in facet_grid/wrap. For more help please provide [a minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) including a working code example and a snippet of your data or some fake data. – stefan Jun 19 '23 at 23:12

0 Answers0