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

Sort not working in multiplot when using 'by = 'model'' #24

Open
victorhartman opened this issue Jan 10, 2022 · 2 comments
Open

Sort not working in multiplot when using 'by = 'model'' #24

victorhartman opened this issue Jan 10, 2022 · 2 comments

Comments

@victorhartman
Copy link

The coefplot package has been very useful in creating graphs that easily and clearly explain results. Thank you for that!

Now I am trying to compare coefficients between different models, in effect comparing countries. However I am having a hard time getting the sort option to work. It does not seem to do anything when using 'by = 'model''. Also is it possible to reverse the sort order?

My code looks like this. I have several logit models with all the same coefficients.

coefplot::multiplot(`logit_model_Belize_2015-2016`,
                    `logit_model_Costa Rica_2011`,
                    logit_model_Cuba_2019,
                    `logit_model_Dominican Republic_2014`,
                    logit_model_Guyana_2014,
                    logit_model_Mexico_2015,
                    logit_model_Panama_2013,
                    logit_model_Suriname_2018,
                    `logit_model_Trinidad and Tobago_2011`,
                    `logit_model_Uruguay_2012-13`,
                    coefficients = "weighted_excluded",
                    names = c("Belize",
                              "Costa Rica",
                              "Cuba",
                              "Dominican Republic",
                              "Guyana",
                              "Mexico",
                              "Panama",
                              "Suriname",
                              "Trinidad",
                              "Uruguay"),
                    sort = 'magnitude',
                    by = "Model")
@jaredlander
Copy link
Owner

Sorting the coefficients with multiplot() is tough. What do you do when for model 1 the order should coefficients a,c,b and for model 2 the coefficients should be a,b,c? By the nature of {ggplot2} all the points for a have to be together, and for b, etc.

If this were a tabular display you could have a two-stage sort, first by model then by coefficient. I'm not sure how to implement this for plots though.

If you have any ideas I'm happy to see what I can do.

@victorhartman
Copy link
Author

Thanks for the response. I understand the difficulty of making this possible. My knowledge on R is however limited, so I don't think I can be of much help.

Is it however not easier in my case when I only select one coefficient (all my models are also exactly the same)?

My original issue, which is btw much easier, was that the names I provided did not sort in ascending order. I fixed this by adding + scale_y_discrete(limits = rev) at the end.

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

2 participants