R Likert包 - 更改标签级别

时间:2014-01-29 22:10:51

标签: r graphing

我正在使用Likert R包来生成图表。我有以下最小的R例子:

library("likert")

group = c("One", "Two", "One", "Two", "One")
response = c(1, 2, 3, 3, 4)
df = data.frame(response)
levels = c("Strongly Disagree", "Disagree", "Neither Agree nor Disagree", "Agree", "Strongly Agree")
df$response = recode(df$response, from=c(1, 2, 3, 4, 5), to=levels)
df$response = as.factor(df$response)
df$response = factor(df$response, levels=levels)

likert_data = likert(df, grouping=group)

plot(likert_data, legend.position="right", plot.percents=FALSE, plot.percent.low=FALSE, plot.percent.high=FALSE, plot.percent.neutral=FALSE, group.order=c("One", "Two"))
+ ggtitle("Title Here")
+ theme(axis.text.y = element_text(colour="black", size="10", hjust=0))
+ theme(axis.text.x = element_text(colour="black", size="10"))

这会生成一个图表,但是,在右侧的“Response”标签中,它只列出了5个Likert选项中的4个。它缺少“非常同意”,因为它不是数据点。

  • 如何强制它列出标签中所有级别的Likert数据?(编辑:已解决,请参阅注释)
  • 如何将左侧的组标签更改为我指定的名称?

1 个答案:

答案 0 :(得分:2)

也许像这样的开始。您必须使用图表中的颜色替换fill = c(1:5)。

library(likert)
library(reshape)

plot.new()
plot(likert_data, legend = "", plot.percents=FALSE, plot.percent.low=FALSE, plot.percent.high=FALSE, plot.percent.neutral=FALSE, group.order=c("One", "Two"))
legend(x = .7, y = .5, fill = c(1:5), legend = levels)