The only good way to do this is to rearrange your data according to the needs of the ggplot function. However, if you want to do it all right, you can. You just need to change the data manually, for example:
ggplot(data=data.frame(value=c(d$A, d$B), variable=c(rep("A",10),rep("B",10))), aes(x=c(1:10,1:10), y=value, fill=variable))+geom_bar(stat="identity", position="dodge")
Here I created a new data array from the old one and assigned the corresponding variable names (this is what the reshape2 package does with the melt function). Then I manually set the x values ββto 1:10 for "A" and 1:10 for "B" so that the bars are displayed next to each other, and not everything is ok from 1:20. I added the argument "fill" to change the colors of the columns to represent "A" or "B".
Dinre
source share