0

I have a summary statistics from the responses to a questionaire item. Further the summary statistics is by several groups (in this case political parties). I would like to create a net stacked bar plot with centering around the neutral category, which is the 3 level ("Neither disagree nor agree") of the response variable in the data frame.

In particular, my available summary of the responses looks like follows.

  Group  Strongly Agree  Agree  Neither disagree or agree  Disagree  Strongly disagree 
  NV.A     35.1           43.8            3.69                  10.9   7.24
  OpenVLD  37.8           19.8           11.30                  17.9  13.30
  SP.A     24.5           11.1           23.50                  19.0  22.10
  Groen    18.2            5.7           35.70                  13.2  27.20
  CD&V     29.2           17.9           12.90                  20.4  19.80

Simply to put everything together into one data frame.

plot.data<-data.frame(
response =     c(rep("Strongly disagree",5),rep("Disagree",5),
               rep("Neither agree nor disagree",5), 
               rep("Agree",5),rep("Strongly agree",5)),

group = c(rep(c("SP.A","Groen","CD&V","OpenVLD","N-VA"),5)),

percentage = c(23.5,35.7,12.9,11.3,3.69,22.1,27.2,19.8,13.2,7.24,19.0,
13.2,20.4,17.9,10.9,24.5,18.2,29.2,37.8,35.1,11.1, 5.70,17.9,19.8,43.8)
)

My current solution is to simply create a stacked bar chart without centering. Is there a way to achieve the centering of the stacked bar chart?

library(ggplot2)

ggplot(plot.data, aes(x=group, y=percentage, fill=response)) + 
geom_bar(stat="identity") +
scale_fill_manual(values=c('#ca0020','#92c5de','#0571b0','#f7f7f7','#f4a582'))+
coord_flip()+
theme_minimal()
S.K.
  • 365
  • 1
  • 3
  • 17
  • I've seen examples without the middle category, such as [here](http://stackoverflow.com/questions/13421141/ggplot-geom-bar-stack-and-center), that are pretty straightforward to code in ggplot2. You might also be interested in the `likert` package, see [here](http://jason.bryer.org/likert/) – aosmith May 17 '17 at 18:04
  • I couldnt get the examples from likert to work for me but the description was very useful [here](https://rpubs.com/m_dev/likert_summary) – S.K. May 19 '17 at 16:23

1 Answers1

0

My solution to plot a net stacked barplot was to first spread the different responses into seperate columns and then plotting it with the plot function from the likert package.

library(likert)
library(tidyr)   
plot.wide<-plot.data.politic%>% spread(response, percentage)
plt.wide.lk<-likert(summary=rename(plot.wide,"Item"=group))
plot(plt.wide.lk)
S.K.
  • 365
  • 1
  • 3
  • 17