Question

I'm using the Likert R package to generate graphs. I have the following minimal R example:

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"))

This generates a graph, however, in the "Response" label on the right, it only lists 4 of the 5 Likert options. It's missing "Strongly Agree" because it wasn't a data point.

  • How can I force it to list all levels of the Likert data in the label? (edit: resolved, see comment)
  • How can I change the group labels on the left to a name that I specify?

No correct solution

OTHER TIPS

Perhaps something like this as a start. You would have to replace fill = c(1:5) with the colors in the graph.

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)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top