小编Nat*_*lie的帖子

R ggplot,geom_text 在标签命令中圆形标签?

现在我可以通过 ggplot geom_bar 中的条形获取上面填充值的标签。但我似乎无法做的是更改标签的小数位数。现在它有 9 位小数,而我只想要 2 位。我尝试使用 round() 和digits=,但没有成功。我认为我不确定将它们放在我的代码中的哪里。

比例是我想要仅标记小数点后两位的比例

谢谢你!

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)
Run Code Online (Sandbox Code Playgroud)

r ggplot2 geom-bar geom-text

6
推荐指数
0
解决办法
1万
查看次数

标签 统计

geom-bar ×1

geom-text ×1

ggplot2 ×1

r ×1