R geom_bar 和 facet_grid 标签在条的顶部
R geom_bar and facet_grid labels on top of bars
我正在努力使这张图看起来更好,但我受制于标签(在本例中为数字)。我怎样才能让他们显示在他们通讯栏的顶部?请注意它是 facet_grid。
我有以下代码和输出:
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
里面
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)
我正在努力使这张图看起来更好,但我受制于标签(在本例中为数字)。我怎样才能让他们显示在他们通讯栏的顶部?请注意它是 facet_grid。 我有以下代码和输出:
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
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)