简体   繁体   中英

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

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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