在r中创建Likert比例图的问题

时间:2016-12-28 10:39:41

标签: r plot bar-chart stacked-chart

我正在尝试绘制使用李克特量表测量的研究数据。我正在使用'Likert' package。当我尝试将图中的数据分组时,我遇到了问题。为了说明,我将演示使用在许多在线演示中使用的数据集,例如
this one

当我运行代码时,我希望/期望一个看起来像这样的图形(注意条形图是按照从“非常不同意”到“非常同意”的良好有序序列组织的): enter image description here

当我运行以下代码时,我得到一个图表,其中订单混淆;主要是“同意”和“非常同意”被交换。任何人都可以解释为什么会发生这种情况以及如何解决这个问题?任何帮助将不胜感激。

require(likert)
library(plyr)

##### import built-in data
data(pisaitems)

# extract data for analysis
items24 <- pisaitems[,substr(names(pisaitems), 1,5) == 'ST24Q']

# rename cols
items24 <- rename(items24, c(
  ST24Q01="I read only if I have to.",
  ST24Q02="Reading is one of my favorite hobbies.",
  ST24Q03="I like talking about books with other people.",
  ST24Q04="I find it hard to finish books.",
  ST24Q05="I feel happy if I receive a book as a present.",
  ST24Q06="For me, reading is a waste of time.",
  ST24Q07="I enjoy going to a bookstore or a library.",
  ST24Q08="I read only to get information that I need.",
  ST24Q09="I cannot sit still and read for more than a few minutes.",
  ST24Q10="I like to express my opinions about books I have read.",
  ST24Q11="I like to exchange books with my friends."))

# capture Likert data by group
l24g <- likert(items24[,1:11], grouping=pisaitems$CNT)

# plot
plot(l24g)

enter image description here

0 个答案:

没有答案