Could anyone help me figure out how to:
- Use
geom_textto show labels only for thosedownandupcategories (how to removestablelabels) - How to manually change negative labels to positive ones (erase minus sign from negative labels)
- How efficiently use
hjustto nudge positive labels to right and negative ones to left of the bars (I try something but wonder if there is better way than just doing it for all data one-by-one)
My desired output would be like this one below:

Code:
x <- LETTERS[1:11]
y <- c(9, 4, 6, 8, 5, 7, -9, -4, -6, -8, -5)
z <- seq(-1, 1, by = 0.2)
dat <- data.frame(x, y, z)
dat %>%
filter(x != "B") %>%
ggplot(aes(fct_reorder(x, y, .desc = T), y,
fill = ifelse(z > 0.7, "up",
ifelse(z < -0.6, "down", "stable")))) +
geom_col() +
scale_fill_manual("Color",
values = c("up" = "#5b3b71",
"down" = "#9a4054",
"stable" = "#b7c1bd")) +
geom_text(aes(label = paste0(y,"%")),
hjust = c(-1,-1,-1,-1,-1,1,1,1,1,1)) +
coord_flip() +
theme_void()
Any help and advice would be much appreciated.
datfor this.abs()ingeom_text()try this:
outcome is: