2

I'm trying to produce an R plot with likert scale data using RStdudio v1.0.153. I get the following error:

Error in likert(think) :
All items (columns) must have the same number of levels

Link to my data is at: https://docs.google.com/spreadsheets/d/1TYUr-_oX9eADZ6it1w_4CQJ_wITP6xISaJJHTad3JbA/edit?usp=sharing

Below is the R code I used:

> library(psych)
> library(likert)

> myColor <- c("red","orange", "light blue","light green", "lavender")
> levels = c("Strongly Disagree", "Disagree", "Neutral", "Agree", "Strongly Agree")

> think$A = factor(think$A, levels, ordered = TRUE)
> think$B = factor(think$B, levels, ordered = TRUE)
> think$C = factor(think$C, levels, ordered = TRUE)
> think$D = factor(think$D, levels, ordered = TRUE)
> think$E = factor(think$E, levels, ordered = TRUE)
> think$F = factor(think$F, levels, ordered = TRUE)

> results <- likert(think)
> plot(results, col = myColor) #Have not used this yet because of the error above
Masssly
  • 29
  • 1
  • 7
  • It's harder to help you when data is located on some external site. See [how to create a reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) for ways to make your question self-sufficient. If we can't copy/paste the code to run and test it, it's more time consuming to help you. – MrFlick Oct 09 '17 at 14:47

1 Answers1

2

The likert command needs a data frame as input.
You should use likert(as.data.frame(think)).

library(psych)
library(likert)
library(readxl)
think <- read_xlsx(path="ThinkData.xlsx")

myColor <- c("red","orange", "light blue","light green", "lavender")
levels = c("Strongly Disagree", "Disagree", "Neutral", "Agree", "Strongly Agree")

think$A = factor(think$A, levels, ordered = TRUE)
think$B = factor(think$B, levels, ordered = TRUE)
think$C = factor(think$C, levels, ordered = TRUE)
think$D = factor(think$D, levels, ordered = TRUE)
think$E = factor(think$E, levels, ordered = TRUE)
think$F = factor(think$F, levels, ordered = TRUE)

results <- likert(as.data.frame(think))
plot(results, col = myColor) 

enter image description here

Marco Sandri
  • 23,289
  • 7
  • 54
  • 58