0

I am trying to plot the following Likert item:

    structure(list(`Likelihood of attending more frequently` = structure(c(4L, 
4L, 4L, 3L, 4L, 4L, 3L, 4L, 5L, 4L, 4L, 4L, 4L, 5L, 3L, 5L, 4L, 
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 1L, 4L, 5L, 4L, 3L, 2L, 3L, 
3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 2L, 5L, 4L, 4L, 4L, 3L, 
4L, 5L, 3L, 3L, 2L, 4L, 4L, 3L, 4L, 1L, 3L, 3L, 4L, 5L, 4L, 4L, 
4L, 4L, 4L, 3L, 4L, 4L, 5L, 4L, 2L, 5L, 3L, 2L, 3L, 3L, 5L, 4L, 
4L, 2L, 3L, 2L, 4L, 5L, 3L, 4L, 4L, 4L, 4L, 5L, 4L, 4L, 3L, 4L, 
4L, 4L, 5L, 3L, 3L, 4L, 3L, 4L, 3L, 3L, 5L, 5L, 4L, 4L, 5L, 2L, 
1L, 4L, 4L, 4L, 1L, 4L, 3L, 2L, 4L, 4L, 4L, 4L, 5L, 4L, 5L, 4L, 
5L, 4L, 2L, 5L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 2L, 3L, 
3L, 4L, 4L, 4L, 5L, 5L, 4L, 5L, 5L, 3L, 2L, 4L, 5L, 5L, 1L, 5L, 
2L, 1L, 5L, 4L, 1L, 4L, 5L, 4L, 2L, 4L, 4L, 4L, 5L, 3L, 2L, 5L, 
5L, 5L, 4L), .Label = c("Highly unlikely", "Somewhat unlikely", 
"Neither likely nor unlikely", "Somewhat likely", "Highly likely"
), class = "factor"), Reason = structure(c(1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 4L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 7L, 7L, 7L, 7L, 7L, 7L, 
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 6L, 6L, 6L, 
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L), .Label = c("Class times conflict with my schedule", 
"I am not interested in the content offered", "I don't have time", 
"I don't have transportation", "I don't know where to find information on classes, programs, and events", 
"Other", "There are not classes near me"), class = "factor")), row.names = c(NA, 
-180L), class = "data.frame")

When I check the factor levels of rhe group items it displays 7 , however, the likert.bar.plot has 9 groups as 2 are duplicated.

like<-likert(freq[, c(1), drop=FALSE], grouping = freq$Reason)
likert.bar.plot(like,wrap.grouping = 40)

I have checked to see if the text strings are different, but they are exactly the same. Any idea what could be causing this?

enter image description here

Chris Bova
  • 134
  • 1
  • 2
  • 9
  • Unfortunately your issue is not reproducible with the example data you provided. However, from the image you posted your duplicated groups are actually different, i.e. it looks as if the labels for some obs. include a line break. Hence, the groups are treated as different categories. – stefan Jan 07 '22 at 12:21
  • I could include the entire dataset if that helps, but the breaks were created when I used wrap.grouping – Chris Bova Jan 07 '22 at 12:22
  • 1
    @stefan I have included the whole df. For some strange reason wrap.grouping only worked on non-duplicated groups. – Chris Bova Jan 07 '22 at 12:25
  • 1
    Hm. Weird. This looks like a bug to me. I had a closer look at the plotting code. As far as I get it the issue is that for the bars the unwrapped group labels are used, while for the percentage labels the wrapped ones are used. Hence we end up with duplicated groups. – stefan Jan 07 '22 at 13:02
  • Interesting, I'll post the issue on github. It looks like @jbryer is pretty good about responding to bugs. Thanks for helping idenify the issue, even if we couldn't solve it. – Chris Bova Jan 07 '22 at 13:06
  • Do that. And see the workaround I just added as an answer. – stefan Jan 07 '22 at 13:08

1 Answers1

1

As I already mentioned in my comment this looks like a bug to me. Both from the source code of likert.bar.plot and from the image it looks as if for the bars the unwrapped group labels are used, while for the percentage labels the wrapped ones are used. Hence we end up with duplicated groups.

However, as a workaround you could wrap the group labels manually before passing to likert. To make this work you also have to set the same width for the wrap.grouping argument:

library(likert)

levels(freq$Reason) <- stringr::str_wrap(levels(freq$Reason), width = 40)
like <- likert(freq[, 1, drop = FALSE], grouping = freq$Reason)
likert.bar.plot(like, wrap.grouping = 40)

stefan
  • 90,330
  • 6
  • 25
  • 51
  • 1
    That definitely worked and is what I was trying to do with the axis lebel. Your workaround will be very useful going forward. Bug report has been filled out. – Chris Bova Jan 07 '22 at 13:27