0

I am following this answer as a guide, but the labels are appearing in the wrong place. Does anyone know what might be causing this?

library(ggplot2)

Macrorregião <- c("Norte", "Nordeste", "Sudeste", "Sul", "Centro-Oeste")
Destino <- c("Despesa", "Água", "Esgoto", "Outros")
Valor <- 1:20

DF <- expand.grid(Destino = Destino,
                  Macrorregião = Macrorregião)

DF$Valor <- Valor

ggplot(data = DF,
     aes(x = Macrorregião,
         y = Valor)) +
 geom_col(aes(fill = Destino)) +
 geom_text(aes(label = Valor),
           position = position_stack(vjust = 0.5))

enter image description here

Daniel Valencia C.
  • 1,749
  • 2
  • 15
  • 32
  • 3
    Add `group = Destino` in the text layer's `aes()`. The ordering between text and bars isn't the same. – teunbrand Feb 02 '22 at 12:43

0 Answers0