我正在尝试在堆积的条形图中添加百分比标签。我可以添加什么到geom_bar中以显示堆积条形图中的百分比标签?
这是我的数据
myresults=data.frame(
manipulation=rep(c(-20,-10,10,20,-20,20)),variable=rep(c("a","a","f","l","l")),value=c(73,83,76,75,78,261,301,344,451,599,866,816,780,674,523))
This is my bar chart,without percentage labels.
我对此一无所知。我在“ gglot堆积条形百分比标签”上进行了搜索,发现可以使用“ + geom_text(stat =“ count”)“来添加百分比标签。
但是,当我在ggplot geom_bar中添加+ geom_text(stat =“ count”)时,R表示“错误:不得将stat_count()用于美观。”我试图弄清楚什么是y美学,但是还不是很成功。
这就是我所做的:
mydata <- ggplot(myresults,aes(x=manipulation,y=value,fill=variable))
mydata + geom_bar(stat="identity",position="fill",colour="black") + scale_fill_grey() + scale_y_continuous(labels=scales::percent) + theme_bw(base_family="Cambria") + labs(x="Manipulation",y=NULL,fill="Result") + theme(legend.direction="vertical",legend.position="right")