我正在尝试使用RStdudio v1.0.153生成具有Likert比例数据的R图。我收到以下错误:
Error in likert(think) :
All items (columns) must have the same number of levels
我的数据链接位于:https://docs.google.com/spreadsheets/d/1TYUr-_oX9eADZ6it1w_4CQJ_wITP6xISaJJHTad3JbA/edit?usp=sharing
以下是我使用的R代码:
> 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
答案 0 :(得分:1)
likert
命令需要数据帧作为输入。
您应该使用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)