Reputation: 23
I am working with a side-by-side bar chart and facing a common issue of overlapping labels. I have looked through previous queries and none seem to work for me and I don't know why.
Below is the command I have and the results
ggplot(data=SEM_Breakdown_2,aes(x=DMA_Clean, y=AQH)) +
geom_bar(aes(fill=SEM),
stat="identity",position=position_dodge(width=1)) +
geom_text(aes(label=round(AQH,digit=0),ymax=AQH),
position=position_dodge(width=1),vjust=-1,size=5)
Just want to show the labels at each columns so I can actually ready them.
modified my code and below, while not perfect it works
geom_text(aes(label=round(Unique..IPs,digit=0),ymax=Unique..IPs),position=position_dodge(width=1),vjust=-1,hjust=ifelse(SEM_Breakdown_2$SEM=="Yes",-0.4,1.4),size=4)
Upvotes: 1
Views: 247
Reputation: 4175
Add an additional parameter to the aes()
call, x=offset
, and make the value dependant on whether the bar is a "yes" bar or a "no" bar.
For instance, x = ifelse( test.if.yes.bar, 5, -5)
Upvotes: 1