Graphic text position using ggplot2

Asked

Viewed 1,312 times

2

I need to adjust the position of a text in the bar graph so that it is above the bar. Below the code used

base.total %>%
  group_by(SEXO, REGIME.JURIDICO.FINAL)%>%
  count() %>%
  ggplot(., aes(x=reorder(SEXO, -n), y=n, fill = REGIME.JURIDICO.FINAL)) +
  geom_bar(stat="identity", width = 0.2, position = "dodge") +
  labs(title = "Gráfico 11: Quantidade de Inativos Civis e Militares",
       subtitle = "Fonte: Base de Dados SIGRH", x = "Sexo", y="Quantidade") + 
  theme(axis.line.x = element_line(size = .5, colour = "black"),
        axis.line.y = element_line(size = .5, colour = "black"),
        axis.text.x = element_text(colour = "black", size = 7),
        axis.text.y = element_text(colour = "black", size = 7),
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(), 
        panel.background = element_blank(),
        legend.title = element_blank()) +  
  geom_text(aes(label = n), size = 3.0, position = position_dodge(width = 0.2))

Resultado do código acima

1 answer

3


I found a suggestion in the Stack Overflow in English (in this topical). Adapting to your example, would look like this

geom_text(aes(label=n, y = n+0.01), size = 3.0, position = position_dodge(width = 0.2))
  • I added geom_text(aes(label = n, y = n+1), size = 3.0, position = position_dodge(width = 0.2)) And nothing happened

  • tries to add a higher value because of the axis scale y

  • 1

    I managed to solve the geom_text(aes(label = n, y = n+3000), size = 3.0, position = position_dodge(width = 0.2)) to solve the problem.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.