I have gone through and followed this guide on how to make stacked bar plots with percentages: Plot stacked bar chart of likert variables in R
Issue 1: it has organised the bars alphabetically, not in the order I had them.
Issue 2: I have Before and After responses for each of 5 questions and I cannot figure out how to have "Before" "After" underneath each stacked plot, and then below that have "Question 1".
Issue 3: I also would like to have the groups of 2 stacked plots for each question, separated from the other questions a little bit.
Here is a snippet of my data:data
This is the code I have used:
graphdata3 <- graphdata3 %>% gather(key='Question_num', value='Answer', -Participant)
graphdata3$Answer <- factor(graphdata3$Answer,
levels=5:1,
labels=c('Strongly Agree','Agree','Neutral','Disagree','Strongly Disagree'))
ggplot(graphdata3, aes(x=Question_num)) +
geom_bar(aes(fill=Answer), position="fill") +
scale_fill_brewer(palette='Spectral', direction=-1) +
scale_y_continuous(expand=expansion(0), labels=scales::percent_format()) +
labs( x='Questions', y='Proportion of Answers (%)') +
theme_classic() +
theme(legend.position='top')