Oscar
Oscar

Reputation: 457

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: enter image description here

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!

Upvotes: 0

Views: 2805

Answers (1)

Oscar
Oscar

Reputation: 457

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)

enter image description here Thanks!

Upvotes: 1

Related Questions