I am using R's likert package to graph survey responses. When using the grouping option and at least one group of responses are all negative or positive, the graph is messed up (see picture). Any workarounds or is this a bug?
library(likert)
grouplabel <- c(rep("A", 6), rep("B", 6), rep("C", 6))
surveyresult <- factor(c(4, 5, 7, 2, 3, 4,
5, 6, 7, 5, 6, 7,
1, 2, 1, 2, 3, 1))
df <- data.frame(grouplabel, surveyresult)
mylikert <- likert(df[,2, drop=FALSE], grouping = df[,1], nlevels=7)
plot(mylikert)
I have tried rearranging the levels of 'grouplabel' and various different data files with the same issue.
This does seem to be a bug in the
likert
package. When you doplot(mylikert)
the function callslikert:::likert.bar.plot()
. If you follow that through, it creates a bunch of data and scalars. However, the three objects it creates -results
,results.low
andresults.high
are enough to replicate the problem.The code below generates the base graph. All the other graphical code in the function is really styling. Again, this is enough to replicate the problem. The issue is that the function strips out all the zero entries, so the
results.low
object does not have anyB
values in it. This doesn't seem to cause a problem for theresults.high
object, which doesn't have anyC
values in it. Nonetheless, the output shows that theresults.low
bars each plot across some of the range ofB
.If you add a zero value for
B
intoresults.low
you get the desired result. Unfortunately, you don't usually get to intervene at this stage since all this happens internally to the function. You may want to file a bug report on the GitHub repoCreated on 2023-10-13 with reprex v2.0.2