简体   繁体   English

在ggplot R中标记geom_bar

[英]Labels geom_bar in ggplot R

I have this code 我有这个代码

ggplot(authors_interest_sex_count, aes(Country, freq, fill=Gender)) + 
geom_bar(stat="identity", position="dodge") + geom_text(aes(label = freq), vjust=-1)

and I got this image: 我得到了这张图片: 在此处输入图片说明

as you can see, the labels for each country are completely vertical, and I think the optimal solution would having each label on top of their column. 如您所见,每个国家/地区的标签都是完全垂直的,我认为最佳解决方案是将每个标签放在其列的顶部。 What should I change or add in my code? 我应该更改或添加什么代码? Thanks in advance! 提前致谢!

As Roman Luštrik commented, the answer I was looking for is 正如RomanLuštrik所说,我一直在寻找答案

ggplot(authors_interest_sex_count, aes(Country, freq, fill=Gender)) + 
geom_bar(stat="identity", position="dodge") + 
geom_text(aes(label = freq), position=position_dodge(width=0.9), vjust=-1)

在此处输入图片说明 Thanks! 谢谢!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM