Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Facet order reverts to alphabetical in grouped bar plot #119

Open
JakeC007 opened this issue May 5, 2021 · 5 comments
Open

Facet order reverts to alphabetical in grouped bar plot #119

JakeC007 opened this issue May 5, 2021 · 5 comments

Comments

@JakeC007
Copy link

JakeC007 commented May 5, 2021

I would like to reopen issue #67. Much like that poster, I am finding that regardless of the order of columns in the original data frame, the facts are displayed in alphabetical order.

UPDATE: After poking around this seems to only be an issue for when the percentage arguments are set to true. If any of the following are set to true the order switches to alphabetical:

  • plot.percent.low
  • plot.percent.high
  • plot.percent.neutral

If they are all set to false, the facet ordering follows the columns in the original data frame. My guess is that something is a bit wonky when the function is asked to calculate percents.

@g-pacheco
Copy link

I would love to see a solution to this :)

@bokazza
Copy link

bokazza commented Jan 16, 2022

I use a cheap trick, which won't work for everyone but will for some (e.g. me). If you don't want the package to alphabetize your items you can "pre-alphabetize" them yourself in the original order. Consider:

`library(likert)
data("pisaitems")
items24 <- pisaitems[,substr(names(pisaitems), 1,5) == 'ST24Q']
names(items24) <- c(
"I read only if I have to.",
"Reading is one of my favorite hobbies.",
"I like talking about books with other people.",
"I find it hard to finish books.",
"I feel happy if I receive a book as a present.",
"For me, reading is a waste of time.",
"I enjoy going to a bookstore or a library.",
"I read only to get information that I need.",
"I cannot sit still and read for more than a few minutes.",
"I like to express my opinions about books I have read.",
"I like to exchange books with my friends.")

Insert this loop [only with grouped, the simple one is pre-ordered high to low, not alphabetically]

nms <- names(items24)
for(i in 1:length(nms)){
nms[i] <- paste("(", letters[i], ") ", nms[i], sep = "")
}
names(items24) <- nms

Resume the vignette

l24 <- likert(items24) # not grouped does not need this

plot(l24)

l24g <- likert(items24, grouping = pisaitems$CNT)
plot(l24g)
`

@bokazza
Copy link

bokazza commented Jan 16, 2022

Sorry for messy formatting :)

@SArsenii
Copy link

Still a problem.

@olizardo
Copy link

I found a solution that worked for me.

create a likert object from your data.
mylikert <- likert(mydata, grouping = mydata$group)

Plot it
myplot <- plot(mylikert)

And this is the main step, relevel the factor that likert uses for the facets inside the ggplot facet_wrap call. This variable is a column called "Item" inside the myplot$data object. As follows:
newplot <- myplot + facet_wrap(~factor(Item, levels = c("lev1", "lev2, "lev3")))

Where c("lev1", "lev2, "lev3") is the orders of the facets that you want.

If you plot newplot you should have the desired ordering (at least worked for me).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants