[R] space between bars of a group in ggplot2

azam jaafari @z@mj@@|@r| @end|ng |rom y@hoo@com
Mon Dec 14 21:16:24 CET 2020


Hello Dear
I want to make a barplot for groups with three repetitions and same values. dataset is like this: 

groups:                  a                              b                        c
value:           1.2, 1.2, 1.2             2.5, 2.5,2.5           
Condition:     sat, sat, sat,         unsat,unsat,unsat,     

that bars fill based on "condition"
I used the below code: 

data%>%ggplot(aes(x=factor(groups), y=value, fill=factor(condition), group=condition)) +
  geom_bar(olour="black",stat="identity", position = position_dodge(width = 0.8), width=0.7)+
scale_y_continuous(breaks=seq(0, 6.5, 1),limits=c(0, 6.5),expand=c(0,0))+ 
scale_x_discrete(expand=c(0.000001,0))+
 theme( axis.line = element_line(colour = "darkblue", 
                      size = 1, linetype = "solid"))+
labs(x = "group Code", y = "Z") +
    theme(panel.background = element_rect(fill = 'white'))+labs(fill = "Condition")+
 theme(axis.text.x = element_text(face='bold',size=8, color='black', angle = 90, vjust = 0.5)) +
 theme(axis.text.y = element_text(face='bold', size=8, color='black'))


but it makes the connected bars (without any space between values) for each group, while I want to add a space between bars for  each value of each group. 

Thank you for helping
BestAzam

	[[alternative HTML version deleted]]



More information about the R-help mailing list