1

I have this table:

a   b   c   d
A   55  2   0.07
A   123 1   0.05
B   222 2   0.04
B   234 1   0.03
C   233 2   0.03
C   187 1   0.04
D   564 2   0.06
D   325 1   0.01
E   112 2   0.02
E   105 1   0.01

I'm plotting a barplot with dots using geom_bar and geom_point. For some reason, the dots are not centered in the middle of the bar. Can somebody help with this?

My code:

ggplot(table, aes(x=a, y=d, fill=as.factor(c))) + 
geom_bar(stat="identity", position="dodge")+
geom_point(aes(y = b / 10000), 
           position = position_dodge(width = 1))

enter image description here

mightaskalot
  • 167
  • 1
  • 14

1 Answers1

0

As mentioned by @s_t, you have to write:

library(ggplot2)
ggplot(d, aes(x=a, y=d, fill=as.factor(c))) + 
  geom_bar(stat="identity", position="dodge")+
  geom_point(aes(y = b / 10000), 
             position = position_dodge(.9))

enter image description here

Data

d = data.frame(a = sort(rep(LETTERS[1:5],2)),
               b = c(55,123,222,234,233,187,564,325,112,105),
               c = rep(c(2,1),5),
               d = c(0.07,0.05,0.04,0.03,0.03,0.04,0.06,0.01,0.02,0.01))
dc37
  • 15,840
  • 4
  • 15
  • 32