6

Right now I can get labels of the fill value above by bars in ggplot geom_bar. But what I can't seem to do is change the number of decimal places of the label. Right now it has 9 decimal places and I only want 2. I have tried using round() and digits= unsuccessfully. I am not sure where to place them in my code I think.

Proportion is what I want labeled with only 2 decimal places

Thank you!

PaperMazeProportion <- ggplot(PM_df, aes(factor(OrientationNum), Proportion, fill=Choice)) +
  stat_summary(fun.y = mean, geom = "bar", position = "dodge") +
  labs(x= "Orientation of Maze",
       title = "Paper Maze Path Choice Penn State; May 07, 2018") +
  theme(plot.title = element_text(hjust = 0.5)) +
  scale_y_continuous(limits= c(0, 0.65)) +
  scale_x_discrete(labels=c("North-South", "South-North", "East-West", "West-East"), breaks=c("1", "2", "3", "4")) +
  geom_text(aes(label=Proportion), position=position_dodge(width=0.9), digits=1, vjust=-0.25, size=3)
Nate
  • 10,361
  • 3
  • 33
  • 40
Natalie
  • 91
  • 1
  • 1
  • 7
  • 6
    You can use something like `geom_text(aes(label = round(Proportion, digits = 2)))` – camille May 09 '18 at 17:09
  • Now I can get it to round, but it is no longer staying on top of my bars + geom_text(aes(label=sprintf("%0.2f", round(Proportion, digits=2), position=position_dodge(width=0.9), vjust=-0.25, size=3))) – Natalie May 09 '18 at 17:14
  • 2
    `geom_text(aes(label=sprintf("%0.2f", Proportion)), position=position_dodge(width=0.9), vjust=-0.25, size=3)` – eipi10 May 09 '18 at 17:16
  • Can you add a sample of your data so folks can take a look at it? – camille May 09 '18 at 18:23

0 Answers0