我开发了一个脚本来绘制李克特量表。脚本可以正常工作,并且情节正确。我想更改响应标签, 在顺序列表中,“完全不同意”,“不同意”,“稍有不同意”,“稍有不同意”,“不同意”,“完全不同意”。 我尝试了不同的解决方案,但似乎都没有效果
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)
答案 0 :(得分:0)
如likert
函数(?likert::likert
)的文档中所述,items
中data.frame的列应为 factors 。然后,级别名称指定在派生李克特图中使用的响应标签。由于您的数据不可重现,请考虑以下人工示例:
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
函数应用于重新编码的数据。框架:
## 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)