0
votes

My question is a continuation for the below question.

Generate paired stacked bar charts in ggplot (using position_dodge only on some variables)

In my data the length of grouping(type) can vary. This makes my bar width, positions inconsistent. I was able to fix my width by dynamically assigning based on the length of group(type). However, the gap between bars is something which I was not able to change as position dodge doesn't work with the stack. Is there a way by which I can change the gaps between the bars ?

1
Post your data and code. - zx8754
data: df <- expand.grid(name = c("oak","birch","cedar"), sample = c("one","two"), type = c("sapling","adult","dead")) df$count <- sample(5:200, size = nrow(df), replace = T) and ggplot command is : ggplot(df,aes(x=sample,y=count,fill=type))+ geom_bar(stat = "identity",color="white")+ facet_wrap(~name,nrow=1) - vishnu

1 Answers

2
votes

Do you mean equal distances between each bar? The code below adds the width argument:

df <- expand.grid(name = c("oak","birch","cedar"), sample = c("one","two"),
                  type = c("sapling","adult","dead")) 
df$count <- sample(5:200, size = nrow(df), replace = T) 

ggplot(df,aes(x=sample,y=count,fill=type))+ 
  geom_bar(stat = "identity", color="white", width = 0.6)+ facet_wrap(~name,nrow=1)

enter image description here