I am using the likert
package in R to plot survey data. For each of nine questions ( 1-5 Likert scale for each), I am grouping the data by men and women.
In the list that is created when I run the likert
command, the names of the nine survey items are stored as a factor variable. However, when I plot the data with the plot
command, the panels in the plot are in a different order than that aforementioned factor variable. The panels are arranged by alphabetical order instead of their level order.
How do I change the order of the panels?
Here is what my likert list looks like (sorry for the pictures, I don't know how else to show you what the data looks like).
l_list <- likert(sLik, grouping = subSurv$gender)
When I do str(l_list)
, it shows that l_list$results$Item
is a factor with 9 levels.
Picture of str(l_list) result
Here is the output of levels(l_list$results$Item)
:
[1] "My peers in class" "The course lecturebook."
[3] "The online videos." "The course blog."
[5] "The instructor, by asking asking questions in class." "The instructor, during office hours."
[7] "Online resources outside blog." "Other students not in class."
[9] "TAs in tutorial room."
All that looks fine, but when I try to plot it, the order of the panels in the plot do not match the order of my survey questions.
plot(l_list, ordered = FALSE, group.order = c("M","F"))
Picture of the likert plot result
Here is the output of 'dput(l_list)' for an abbreviated version of my data (to save space):
structure(list(results = structure(list(Group = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L), .Label = c("M", "F"), class = "factor"), Item = structure(c(1L,
2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L,
9L), .Label = c("My peers in class", "The course lecturebook.",
"The online videos.", "The course blog.", "The instructor, by asking asking
questions in class.",
"The instructor, during office hours.", "Online resources outside blog.",
"Other students not in class.", "TAs in tutorial room."), class = "factor"),
`Completely useless` = c(0, 0, 0, 20, 0, 0, 20, 40, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0), `Somewhat useless` = c(0, 0, 0,
20, 0, 0, 0, 40, 20, 0, 0, 0, 0, 0, 0, 0, 100, 0), `Neither/No opinion` = c(20,
0, 20, 0, 0, 20, 0, 20, 40, 0, 0, 0, 0, 100, 0, 0, 0, 0),
`Somewhat useful` = c(60, 60, 20, 60, 0, 0, 60, 0, 20, 100,
0, 0, 100, 0, 0, 0, 0, 100), `Very useful` = c(20, 40, 60,
0, 100, 80, 20, 0, 20, 0, 100, 100, 0, 0, 100, 100, 0, 0)), .Names =
c("Group",
"Item", "Completely useless", "Somewhat useless", "Neither/No opinion",
"Somewhat useful", "Very useful"), row.names = c(NA, -18L), class =
"data.frame"),
items = structure(list(`My peers in class` = structure(c(5L,
4L, 4L, 3L, 4L, 4L), .Label = c("Completely useless", "Somewhat useless",
"Neither/No opinion", "Somewhat useful", "Very useful"), class =
c("ordered",
"factor")), `The course lecturebook.` = structure(c(4L, 5L,
5L, 5L, 4L, 4L), .Label = c("Completely useless", "Somewhat useless",
"Neither/No opinion", "Somewhat useful", "Very useful"), class =
c("ordered",
"factor")), `The online videos.` = structure(c(3L, 5L, 5L,
5L, 5L, 4L), .Label = c("Completely useless", "Somewhat useless",
"Neither/No opinion", "Somewhat useful", "Very useful"), class =
c("ordered",
"factor")), `The course blog.` = structure(c(1L, 4L, 4L,
4L, 4L, 2L), .Label = c("Completely useless", "Somewhat useless",
"Neither/No opinion", "Somewhat useful", "Very useful"), class =
c("ordered",
"factor")), `The instructor, by asking asking questions in class.` =
structure(c(5L,
5L, 3L, 5L, 5L, 5L), .Label = c("Completely useless", "Somewhat useless",
"Neither/No opinion", "Somewhat useful", "Very useful"), class =
c("ordered",
"factor")), `The instructor, during office hours.` = structure(c(5L,
5L, 5L, 5L, 5L, 3L), .Label = c("Completely useless", "Somewhat useless",
"Neither/No opinion", "Somewhat useful", "Very useful"), class =
c("ordered",
"factor")), `Online resources outside blog.` = structure(c(4L,
5L, 5L, 4L, 1L, 4L), .Label = c("Completely useless", "Somewhat useless",
"Neither/No opinion", "Somewhat useful", "Very useful"), class =
c("ordered",
"factor")), `Other students not in class.` = structure(c(2L,
1L, 2L, 3L, 1L, 2L), .Label = c("Completely useless", "Somewhat useless",
"Neither/No opinion", "Somewhat useful", "Very useful"), class =
c("ordered",
"factor")), `TAs in tutorial room.` = structure(c(5L, 2L,
4L, 3L, 4L, 3L), .Label = c("Completely useless", "Somewhat useless",
"Neither/No opinion", "Somewhat useful", "Very useful"), class =
c("ordered",
"factor"))), .Names = c("My peers in class", "The course lecturebook.",
"The online videos.", "The course blog.", "The instructor, by asking asking
questions in class.",
"The instructor, during office hours.", "Online resources outside blog.",
"Other students not in class.", "TAs in tutorial room."), row.names =
386:391, class = "data.frame"),
grouping = structure(c(1L, 1L, 2L, 1L, 1L, 1L), .Label = c("M",
"F"), class = "factor"), factors = NULL, nlevels = 5L, levels =
c("Completely useless",
"Somewhat useless", "Neither/No opinion", "Somewhat useful",
"Very useful")), .Names = c("results", "items", "grouping",
"factors", "nlevels", "levels"), class = "likert")
Any ideas on how to get the panels in the order of my factor levels for l_list$results$Item
rather than being alphabetical?