My dataset looks like this:
`DSET<-data.frame(cbind(c(rep("V1",3),rep("V2",3),"V3"),
c(rep(c("X1","X2","X3"),2),"X1"),
c(rep(1,7))))`
`names(DSET)<-c("A","B","C")`
`DSET[,3]<-c(1,-2,1,3,-1,2,-3)`
With three grouping variables (V1,V2,V3) and three variables per Group (X1,X2,X3). The Problem is that group 3 (V3) has only one variable (X1) but lacks the two others. If I want to produce a bargraph, now, everything works fine despite the fact that the bar of group 3 is three times as large than the ones in group one and two.
`Grph<-ggplot(DSET,aes(x=A,y=C,fill=B))`
`dodge <- position_dodge(width=0.9)`
`Grph+geom_bar(position=dodge)`
I tried to add two rows with the lacking groups and the value 0 for X2 and X3 and It works somewhat.
`DSET<-data.frame(cbind(c(rep("V1",3),rep("V2",3),rep("V3",3)),
c(rep(c("X1","X2","X3"),3)),c(rep(1,9))))`
`names(DSET)<-c("A","B","C")`
`DSET[,3]<-c(1,-2,1,3,-1,2,-3,0,0)`
`Grph<- ggplot(DSET,aes(x=A,y=C,fill=B))`
`dodge <- position_dodge(width=0.9)`
`Grph+geom_bar(position=dodge)`
But what I would really like to achieve is a plot that adjusts the group size depending on the number of bars each group has by keeping the bar width constant. Is there any way to do this?
looking forward to your help!