7

I created a ggplot2 bar plot and added a label, with the bar y-value, above the bar.

d <- data.frame(
       Ano=2000+5*0:10,
       Populacao =c(6.1,6.5,6.9,7.3,7.7,8.0,8.3,8.6,8.9,9.1,9.3)
     )
d %>% ggplot(aes(x=Ano, y=Populacao)) + geom_bar(stat="identity") +
  geom_text(aes(label=Populacao), vjust=-0.5) 

enter image description here

Notice how the label on the highest column gets cut.

Is there a way for the plot to automatically adjust to the presence of the label?

EDIT: I know I can adjust this manually with scale_y_continuous(breaks=seq(0, 10, 1), limits=c(0,10))

tonytonov
  • 25,060
  • 16
  • 82
  • 98
LucasMation
  • 2,408
  • 2
  • 22
  • 45

0 Answers0