Geom_label ggplot,将百分比添加到barplot的正确位置,

时间:2019-10-22 10:36:01

标签: r ggplot2

我正在尝试使用geom_label将百分比添加到条形图中。我已经检查了这里提出的其他问题,并尝试应用建议。但是,我一直得到错误的输出,并且似乎无法将文本放在每个小节上。

这是我的代码:

plot_total <- ggplot(answers_sum, aes(y=Percentage,x= factor(type_of_questions,level=c("topic","total answers")), fill=GROUP,color=GROUP))  +  
  geom_bar(stat ="identity",  position= "dodge", width= 0.8) + facet_grid(TEXT~CONDITION)+
  theme_classic() +
  theme(legend.text = element_text(size = 30),strip.text = element_text(size=30),axis.text=element_text(size=34), plot.title=element_text(size = 34, family="Baskerville"),text=element_text(size = 34, family="Baskerville"))+
  xlab("Type of questions")+ ylab("% of correct answers")+
  ggtitle("Accuracy results")+
  scale_fill_manual(values = c("#fa9fb5", "#41b6c4"), breaks=c("control","dyslexia")) +
  scale_color_manual(values = c("#dd3497",  "#1d91c0"), breaks=c("control","dyslexia"))+
  theme(plot.title = element_text(hjust=0.5), legend.title=element_blank()) + 
  theme(panel.background = element_rect(fill = NA, color = "black"))+ geom_label(data = answers_sum, aes(x =type_of_questions, y =Percentage, label = sprintf("%0.2f%%", round(Percentage, digits = 2))), colour="black", fill="white", family = "Baskerville",
                                                                                 position=position_dodge(width=1),vjust = -1,   label.size = NA, size=10) +  ylim(0,115)


plot_total

这是我的输出:

image

有人可以帮忙吗?

0 个答案:

没有答案