Geom_text with dodging panel

I am trying to add text, as in the geom_text position on the evaded barbecue, but it does not work with my simple data

data=data.frame(s=c(10,13,17,8), pr=c("a","b","a","b"), m=c(rep(as.Date('01.01.2015','%d.%m.%Y'),2), rep(as.Date('01.02.2015','%d.%m.%Y'),2))) 

And ggplot

 ggplot(data = data ,aes(x = m, y = s,fill=pr ,ymax = max(s)*1.1))+ geom_bar(position = "dodge",stat="identity")+ geom_text(aes(y=s/2,label=paste(round(s,3),"%")),position = position_dodge(width=1))+ scale_x_date(labels = date_format("%m/%y"),breaks = date_breaks("months")) 

I get

enter image description here

How to add text to the desired position (in the middle of each panel)? Thank!

+5
r ggplot2 bar-chart
Oct 12 '15 at 11:03
source share
1 answer

You can try

 ggplot(data = data, aes(x = as.factor(m), y = s,fill=pr ,ymax = max(s)*1.1)) + geom_bar(position = "dodge", stat="identity") + geom_text(aes(y=s/2,label=paste(round(s,3),"%")),position = position_dodge(.9)) + scale_x_discrete(labels = function(x) format(as.Date(x), "%m/%y")) + xlab("m") 
+5
Oct 12 '15 at 12:10
source share



All Articles