I have tried finding the questions with similar questions but was not fruitful. If this question has already been requested, please guide me there.
How to add space within each bar of the stacked barplots?
df <- data.frame(Type =sample(LETTERS[1:5],14,replace = T),
ET =sample(c('A1','A2','B3','B6','C5'),14,replace = T))
ggplot(df, aes(x=Type, fill = as.factor(ET))) + geom_bar()
For example, space between the two types (colours) within the A
bar.
There is a option of doing it for two variables using the below command but not sure for a single variable plot
ggplot(data, aes(x=xvar,y=yvar,fill=zvar)) + geom_bar(stat="identity")
Tried this command, but did not work:
df %>% group_by(Type) %>% count(ET) %>% data.frame() %>% ggplot(aes(x=Type, y=n, fill = ET)) + geom_bar(stat="identity")