-1

I have the following dataset:

a<-data.frame(time=c("before","after","before","after"),
                  company=c(1,1,2,2),
                  value=c(3.751522,4.776224,3.838707,2.644144 ))

And to plot a graph I used the following code

a$company<-as.factor(a$company)
ggplot(a, aes(x=company, y=value, fill=time)) + geom_col(position="dodge")

As a result, I have the figure for two companies with after and before bars. However, how to fix a problem that the first bar of the company corresponds to the before and next to the after, and not vica versa as in my graph?

John Mayer
  • 103
  • 7

1 Answers1

2

Does this achieve what you want:

a<-data.frame(time=factor(c("before","after","before","after"),
                          levels = c("before", "after")),
              company=c(1,1,2,2),
              value=c(3.751522,4.776224,3.838707,2.644144 ))
a$company<-as.factor(a$company)
ggplot(a, aes(x=company, y=value, fill=time)) + geom_col(position="dodge")
Joe
  • 662
  • 1
  • 7
  • 20