Reputation: 183
I am trying to learn the package cregg
through the tutorial here. The tutorial works fine. However, I have an issue when I try to change the default setting of the functions. It looks like when it plots, the order of the levels and coef dots of the legend is ordered alphabetically or by numbers. My question is that when I have tried two ways: one if through the ggplot function and the second one is to change the order of levels in advance to change the order to, say 31524
, both methods do not work. The original codes are as follow:
data("immigration")
stacked <- cj(immigration, ChosenImmigrant ~ Gender +
Education + LanguageSkills + CountryOfOrigin + Job + JobExperience +
JobPlans + ReasonForApplication + PriorEntry, id = ~ CaseID,
estimate = "mm", by = ~ contest_no)
plot(stacked, group = "contest_no", feature_headers = FALSE)
My question is how I can the order of levels of contest_no
both on the plot and in the legend. One thing I have found is that it seems like the order of levels of contest_no
is determined by the function cj
first (you can check it by stacked[["contest_no"]]
). Thank you!
Upvotes: 0
Views: 529
Reputation: 183
Thanks to @Tung!(I know I left a similar comment but I still want to answer this one and close it) The answer is simple and straightforward but I didn't think it completely. In my question I kind of having the answer but I didn't know why I didn't see it. Since stacked[["contest_no"]]
can show the order of levels of stacked[["contest_no"]]
, I just change the order by stacked[["contest_no"]] <- factor(stacked[["contest_no"]], levels=c(3, 1, 5, 2, 4))
and then plot the whole object of stacked
. It works fine.
Upvotes: 1