我对R非常陌生,请提供一些帮助。我正在尝试从我发送的李克特调查中绘制数据。我得到了一个不错的图,这很好,但是,图中“同意”,“不同意”或“中立”的人数百分比不正确。此外,每次运行绘图代码时,问题的顺序和百分比都会不断变化。
为我的代码提供一些背景信息,有35个人被质疑,他们的李克特量表的意思是“完全同意”,“同意”,“中立”,“不同意”和“非常不同意”。问了20个问题,但是为了简化您的代码,我只写了10个。
到目前为止,这是我的代码:
library(ggplot2)
require(likert)
require(plyr)
require(reshape)
library(reshape2)
responses <- data[c(2:21)]
mylevels <- c('Strongly Agree', 'Agree', 'Neutral', 'Disagree', 'Strongly Disagree')
for(i in seq_along(data)) {
data[,i] <- factor(data[,i], levels=mylevels)
}
ldata <- likert(data)
n.levels <- sapply(data,nlevels)
max.levels <- levels(data[,which.max(n.levels)])
for (i in seq_along(data)) {
mis.lev = which(!max.levels %in% levels(data[,i]))
levels(data[,i]) = append(levels(data[,i]),max.levels[mis.lev])
}
lresponses <- likert(responses)
require(Epi)
for (i in seq_along(data)) {
data[,i] = Relevel(data[,i],mylevels)}
lresponses <- likert(responses)
lgood
mylevels <- c('Strongly Agree', 'Agree', 'Neutral', 'Disagree', 'Strongly Disagree')
myColor <- c("pink","pink1", "pink2","pink3", "pink4")
items <- data.frame(‘Q1’=factor(sample(mylevels[1:5], 35, replace=TRUE)),
'Q2'=factor(sample(mylevels[1:5], 35, replace=TRUE)),
'Q3'=factor(sample(mylevels[1:5], 35, replace=TRUE)),
'Q4'=factor(sample(mylevels[1:5], 35, replace=TRUE)),
'Q5'=factor(sample(mylevels[1:5], 35, replace=TRUE)),
'Q6'=factor(sample(mylevels[1:5], 35, replace=TRUE)),
'Q7'=factor(sample(mylevels[1:5], 35, replace=TRUE)),
'Q8'=factor(sample(mylevels[1:5], 35, replace=TRUE)),
'Q9'=factor(sample(mylevels[1:5], 35, replace=TRUE)),
'Q10'=factor(sample(mylevels[1:5], 35, replace=TRUE)),
items
str(items)
groups <- sample(c('g1','g2'), 35, replace=TRUE)
tryCatch({
# This will throw an error because all the items must have the same number of levels.
lbad <- likert(items)
}, error=function(e) {
print("This is good that an error was thrown!")
print(e)
})
for(i in seq_along(items)) {
items[,i] <- factor(items[,i], levels=mylevels)
}
lgood <- likert(items)
items
summary(lgood)
plot(lgood)
lgr <- likert(items, grouping=groups)
summary(lgr)
plot(lgr)
library(likert)
results <- likert(as.data.frame(items))
plot(results, color= myColor)
衷心感谢您能为我提供的任何帮助!我已经花了一个星期的时间,但我真的很迷失方向!
TLDR问题: 1)我该如何按顺序从第1季度到第10季度回答问题? 2)如何为同意和不同意问题的人获得正确的百分比?
谢谢大家!