R顶部的geom_bar和facet_grid标签 [英] R geom_bar and facet_grid labels on top of bars
本文介绍了R顶部的geom_bar和facet_grid标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图使该图看起来更好,并且我被标签(在这种情况下为数字)所卡住.如何使它们显示在其通讯栏的顶部?注意这是一个facet_grid. 我有以下代码和输出:
I am trying to make this graph look better, and I'm stuck with the labels (the numbers in this case). How can I make them to show on the top of their correspondent bar? Notice it is a facet_grid. I have the following code and the output:
ggplot(articles_europaoccidental_sex_count_unique_group, aes(Country, percentage)) + geom_bar(stat = "identity", position = "dodge", aes(fill=Gender)) +
facet_grid(~Propuesta) + geom_text(aes(label = round(percentage, 2)), position = position_dodge(width = 0.9), vjust = -1)
谢谢!
推荐答案
您快到了,只需要将aes(fill=Gender)
移到ggplot
You are almost there, just you need to move aes(fill=Gender)
to inside ggplot
library(tidyverse)
#Reproducible data set
test_mtcars <- mtcars %>% group_by(cyl,am, gear) %>% summarise(mean = mean(mpg))
ggplot(test_mtcars, aes(as.factor(cyl), mean, fill=as.factor(am))) + geom_bar(stat = "identity", position = "dodge") +
facet_grid(~gear) + geom_text(aes(label = round(mean, 2)), position = position_dodge(width = 0.9), vjust = -1)
这篇关于R顶部的geom_bar和facet_grid标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文