0

My question is related to this answer by stibu. I am using geom_bar and I am trying to center the bars between the x-axis ticks (see the second graph of the answer).

Here is an example:

grp<-letters[1:13]
count<-c(38,591,549,487,419,363,276,276,164,68,31,10,5)
data<-data.frame(grp,count)
ggplot(data,aes(x=grp,y=count))+geom_bar(stat="identity")

Which gives the following:

enter image description here

  • My x axis is made of character variables so I can not use the "+0,5" trick.
  • There is no boundary or center option for geom_bar as suggested here

So how do I align bars so that their left border is aligned with the tick?

I am using R version 3.4.0 and RStudio 1.0.143.

jeake
  • 103
  • 1
  • 7

1 Answers1

4

Is that what you want ?

require(ggplot2)

grp<-letters[1:13]
count<-c(38,591,549,487,419,363,276,276,164,68,31,10,5)
data<-data.frame(grp,count)
ggplot(data,aes(x=grp,y=count))+
  geom_bar(stat="identity",  
           width = 0.9, 
           position = position_nudge(x = 0.5)) 
kluu
  • 2,848
  • 3
  • 15
  • 35