Hello Guys! I have the code below and i would like to use geom_text to put label above the corresponding bar. Could somebody help me? Thank you very much!
library(ggplot2)
library(tidyverse)
# Tibble
TB1 <-tribble(
~Codigo, ~Valor, ~Descricao, ~Categoria, ~Subcategoria, ~Grupo,
1, 4, "aaa", "A", "a", "I",
2, 13, "bbb", "A", "a", "II",
3, 24, "ccc", "A", "b", "II",
4, 36, "ddd", "B", "a", "III",
5, 55, "eee", "B", "a", " I",
6, 89, "fff", "B", "c", "II",
7, 113, "ggg", "B", "d", "II",
8, 313, "ggg", "C", "a", "IV"
)
DADOS <- TB1 %>% group_by(Categoria, Subcategoria, Grupo) %>% summarise(Soma = sum(Valor))
DADOS %>%
ggplot(aes(x = Subcategoria, y = Soma, fill = Grupo)) +
geom_bar(stat = "identity", position = position_dodge(preserve = 'single'))+
geom_text(aes(label=Soma), position=position_dodge(width = 0.9), vjust=-0.5, size=3.5)