0

我开发了一个脚本来绘制李克特量表。脚本工作正常,情节正确。我想在有序列表中更改响应标签,即“非常不同意”、“不同意”、“稍微不同意”、“稍微同意”、“同意”、“非常同意”。我尝试了不同的解决方案,但似乎都不起作用

Q1 <- read_excel("C:\\Users\\users\\Desktop\\Survey Responses\\Business Survey\\BusinessLikert.xlsx")

df <- data.frame(respondent = c(Q1$Respondent), Score = c(Q1$Q1))

df1 <- likert(items=df[,2, drop = FALSE], nlevels = 6)

summary(df1)

likert.bar.plot(df1)

likert.density.plot(df1)

图片

4

1 回答 1

0

likert函数 ( ?likert::likert) 的文档中所述,data.frame 中的列items应该是factor。然后,级别名称指定派生的李克特图中使用的响应标签。由于您的数据不可重现,请考虑以下人工示例:

library(likert)

set.seed(1)
df <- data.frame(Score = factor(sample(1:6, size = 100, replace = TRUE), 
                 labels = c("Strongly Disagree", "Disagree", "Slightly Disagree", "Slightly Agree", "Agree", "Strongly Agree")))
(df_likert <- likert(items = df))
#>    Item Strongly Disagree Disagree Slightly Disagree Slightly Agree Agree
#> 1 Score                19       18                12             15    15
#>   Strongly Agree
#> 1             21

likert.bar.plot(df_likert)


编辑:对于表示data.frame中各个响应组的多个(例如数字)列,首先将列重新编码为因子,然后将likert函数应用于重新编码的data.frame:

## initial data.frame of integers
df <- data.frame(
  sapply(c("Q1", "Q2", "Q3"), function(x) sample(1:6, size = 100, replace = TRUE))
)

## recode each column as a factor
df_factor <- as.data.frame(
  lapply(df, function(x) factor(x, 
      labels = c("Strongly Disagree", "Disagree", "Slightly Disagree", 
                 "Slightly Agree", "Agree", "Strongly Agree"))
  )
)

(df_likert <- likert(items = df_factor))
#>   Item Strongly Disagree Disagree Slightly Disagree Slightly Agree Agree
#> 1   Q1                19       18                12             15    15
#> 2   Q2                19       16                19             18    15
#> 3   Q3                18       15                 8             21    20
#>   Strongly Agree
#> 1             21
#> 2             13
#> 3             18

likert.bar.plot(df_likert)

李克特绘制多个组

于 2019-06-30T19:10:42.193 回答