1

I have the following table. With 'a' and 'b' on a likert scale from 1-5.

type a b
typeOne 2 3
typeTwo 4 4
typeOne 5 2

Now I try to visualize the data as seen here in two groups (typeOne, typeTwo) and with 'a' and 'b' on the y-axis.

Likert Example Image

Unfortunately when I run my factor code all numeric values vanish from the table and get replaced by 'NA'.

My code is:

df <- as.data.frame(data) 

factorLevels <- c('Strongly Disagree', 'Disagree', 'Neither', 'Agree', 'Strongly Agree') 

df[2:3] <- lapply(df[2:3], factor, levels=factorLevels) 

library(likert)
df_likert <- likert(df[,c(2:3)], grouping = df$type) 
plot(df_likert)

When I run the plot command I get the following error:

argument must be coercible to non-negative integer

jay.sf
  • 60,139
  • 8
  • 53
  • 110
Jonas
  • 49
  • 7
  • You will need use revalue or other alternative function to turn your integers into string values first, see - https://stackoverflow.com/questions/36615769/is-there-an-alternative-to-revalue-function-from-plyr-when-using-dplyr – Bulat Oct 23 '21 at 23:06
  • You shouldn't turn them into factors. Are you using the likert package? – Elin Oct 23 '21 at 23:24
  • @Elin Yes, I am using the likert package – Jonas Oct 23 '21 at 23:25
  • Okay that does not want factors, it wants you to assign the labels using its own special methods. Look at https://lmudge13.github.io/sample_code/likert_graphs.html ... You need `ordered=TRUE` – Elin Oct 23 '21 at 23:36

1 Answers1

1

You're confusing levels= with labels=.

fac <- c('a', 'b')

f_labels <- c('Strongly Disagree', 'Disagree', 'Neither', 'Agree', 
              'Strongly Agree')

d[fac] <- lapply(d[fac], factor, levels=1:5, labels=f_labels)

library(likert)
d_likert <- likert(d[fac], grouping=d$type) 
plot(d_likert)

enter image description here


Data:

d <- read.table(text='type  a   b
typeOne     2   3
typeTwo     4   4
typeOne     5   2', header=TRUE)
jay.sf
  • 60,139
  • 8
  • 53
  • 110