R 如何使用ggplot输入带有2位数字的条形图百分比(%)?

R 如何使用ggplot输入带有2位数字的条形图百分比(%)?,r,ggplot2,geom-bar,R,Ggplot2,Geom Bar,我在R方面没有很多技能,我有两个问题。 有人能帮我吗 a) 我想在这张图中用两位数字表示百分比数字,比如(120,07%)。我一直在尝试使用“dplyr”,但我做不到 b)那么,我可以将“y轴”更改为图形中的百分比吗 谢谢 library(ggplot2) ggplot(place, aes(x = Place, y = Dif)) + geom_bar(aes(fill = Dif < 0), colour="black", stat = "identi

我在R方面没有很多技能,我有两个问题。 有人能帮我吗

a) 我想在这张图中用两位数字表示百分比数字,比如(120,07%)。我一直在尝试使用“dplyr”,但我做不到

b)那么,我可以将“y轴”更改为图形中的百分比吗

谢谢

library(ggplot2)
ggplot(place, aes(x = Place, y = Dif)) +
  geom_bar(aes(fill = Dif < 0), colour="black", stat = "identity") +
  scale_fill_manual(guide = FALSE, breaks = c(TRUE, FALSE), values=c("gray", "red")) +
  geom_text(aes(label=Dif), position=position_dodge(width=0.9), vjust=-0.25)

您可以:

库(ggplot)
ggplot(df,aes(位置,Dif/100,填充=Dif>0))+
geom_col()+
几何图形文字(aes(y=Dif/100+0.1*符号(Dif/100),
标签=比例::百分比(Dif/100)))+
geom_hline(yintercept=0)+
比例填充手册(值=c(“红色”、“绿色”),导向=导向无()+
比例是连续的(标签=比例::百分比,name=“Diff”)+
主题_bw()

您可以:

库(ggplot)
ggplot(df,aes(位置,Dif/100,填充=Dif>0))+
geom_col()+
几何图形文字(aes(y=Dif/100+0.1*符号(Dif/100),
标签=比例::百分比(Dif/100)))+
geom_hline(yintercept=0)+
比例填充手册(值=c(“红色”、“绿色”),导向=导向无()+
比例是连续的(标签=比例::百分比,name=“Diff”)+
主题_bw()
aes(label=round(Dif,2))
应该有效
aes(label=round(Dif,2))
应该有效
structure(list(Place = c("Supermarket", "Markets", 
"House", "Consumption", "Hipermarkets", "Comerce", 
"Outdoors sale"), Dif = c(-20.1884514229122, -50.0150282227513, 
5.34342366569214, -2.47231788994851, 25.7466309314144, 120.078289871755, 
24.0501027574048)), row.names = c(NA, -7L), class = c("tbl_df", 
"tbl", "data.frame"))