0

Using this page as a reference http://jason.bryer.org/likert/ I am finding that when I replicate Bryers code with my own data the likert factor levels are in the wrong order. This doesn't seem to happen with the demo code but does with mine.

I plot with

plot(lexam, centered = FALSE, wrap = 30) 

to get the image you see

I tried to amend with the following without success.

levels <- c("Strongly Agree", "Agree", "Neutral", "Disagree","Strongly Disagree")
lexam[] <- lapply(lexam, function(x) factor(x, levels = levels))

Can anybody suggest what I can do to re-order the factor levels for the plot? You should see in the linked image where the problem is. Incorrect Likert Ordering

Interestingly I've seen the same problem in other posts where it's not actually the problem being discussed. For example Plot Percents with Likert Package - Doesn`t work when grouping you can see the same issue even though it's not the topic of discussion.

  • It seems that your problem is rather concerned with reordering factors in R than with the `likert` package. [The subject](https://stackoverflow.com/search?q=reorder+factors+%5Br%5D) of ordering factors in R is as old as this site so you could pick from one of many solutions available through SO. – Konrad Aug 28 '17 at 14:14

1 Answers1

0

You can use the ordered function docs to create an ordered factor. See also this tutorial

levels <- c("Strongly Agree", "Agree", "Neutral", "Disagree","Strongly Disagree")
ordered_factor <- ordered(x, levels = levels)
patrick
  • 4,455
  • 6
  • 44
  • 61
  • Thanks @Patrick. Stupid question but how do I then plot using the ordered factor item created? – H.R.Badger Aug 28 '17 at 14:25
  • @H.R.Badger sorry, my mistake -- you can just add it as a column to your `data.frame`, or overwrite your old column. e.g. if your `data.frame` is *lexam* and the column name *rating*, you can do `lexam['rating'] <- ordered(lexam['rating'], levels = levels)` – patrick Aug 28 '17 at 14:58