double geom_bar,如何获取每个条的值

问题描述 投票:0回答:1

我在两个不同时间段(Y轴)上都有一个国家(X轴)的图表,因此每个国家/地区都加倍。我想查看每个栏的值。我使用了geom_text,但是我在同一行上得到了值,所以它们不在适当的位置。如何为这种类型的绘图使用geom_text?

Rcountry %>%
  gather("Type", "Value",-Country) %>%
  ggplot(aes(Country, Value, fill = Type)) +
  geom_bar(position = "dodge", stat = "identity") + 
  coord_flip()+
  theme_minimal()+scale_fill_grey()+
  theme(legend.position="bottom")+
  theme(legend.title = element_blank())+
  scale_fill_manual(values=c("darkslategray4", "darkslategrey"))+
  labs(x="Country", y="Stock of robots per thousands worker in '000")+
  geom_text(aes(label=c(X2010, X2018)), size=3.5)```

Thank you

ggplot2 geom-bar geom-text
1个回答
0
投票
library(ggplot2) library(dplyr) mtcars2 <- mtcars %>% group_by(cyl, gear) %>% summarise(mpg = mean(mpg)) %>% ungroup() ggplot(mtcars2, aes(x = factor(cyl), mpg, fill = factor(gear))) + geom_bar(position = "dodge", stat = "identity") + theme_minimal() + scale_fill_grey() + theme(legend.position="bottom")+ theme(legend.title = element_blank())+ labs(x="Country", y="Stock of robots per thousands worker in '000")+ geom_text(aes(label = mpg), position = position_dodge(.9), size=3.5) + coord_flip()

“”

reprex package(v0.3.0)在2020-04-15创建

© www.soinside.com 2019 - 2024. All rights reserved.