Search code examples
rlikert

Using plot likert to plot likert scale data


I am using a dataset that has likert scale responses. I am attaching sample observations from the dataset below.

I am always get an error, can someone help me with this?

Thanks

att<-structure(list(att1_goodofall = c(3L, 3L, 1L, 3L, 3L, 3L, 3L, 
2L, 3L, 3L), att2_pvtdisease = c(3L, 3L, 2L, 2L, 3L, 3L, 3L, 
3L, 3L, 3L), att3_curedisease = c(3L, 1L, 3L, 2L, 2L, 1L, 2L, 
3L, 3L, 3L), att4_timewaste = c(4L, 4L, 2L, 3L, 4L, 4L, 4L, 4L, 
4L, 4L), att5_helpgenerations = c(3L, 3L, 3L, 3L, 2L, 3L, 3L, 
2L, 3L, 3L)), row.names = c(NA, 10L), class = "data.frame")


#labelling the values
for(i in att) {                              
  
    val_lab(att)<-make_labels("0 Strongly disagree 
                                          1 Disagree
                                          2 Neither agree or disagree
                                          3 Agree
                                          4 Strongly agree")
}

#plot_likert function
plot_likert(at)

Error in freq[valid] <- counts : 
NAs are not allowed in subscripted assignments

Solution

  • I'm pretty sure that this is a bug but couldn't tell whether it is a bug in expss or in sjPlot.

    However, as workaround you could switch to e.g. sjlabelled::set_labels to label your dataset:

    library(sjPlot)
    library(expss)
    
    att <- sjlabelled::set_labels(att, labels = make_labels("0 Strongly disagree
                                              1 Disagree
                                              2 Neither agree or disagree
                                              3 Agree
                                              4 Strongly agree"))
    
    sjPlot::plot_likert(att, cat.neutral = 3)