# Comparing multiple (g)lm in one graph #rstats

**Strenge Jacke! » R**, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

It’s been a while since a user of my plotting-functions asked whether it would be possible to compare multiple (generalized) linear models in one graph (see comment). While it is already possible to compare multiple models as table output, I now managed to build a function that plots several (g)lm-objects in a single ggplot-graph.

The following examples are based on a development snapshot of my sjPlot package. You can download the script of the `sjp.glmm`

function here (the latest release of my package probably has to be installed to run the script due to dependencies on other help-functions that are not included in the script). *Please note that this script will not be updated! It will be included in the next update of my package!*

Once you’ve compiled the script, you can run one of the examples provided in the function’s documentation:

# prepare dummy variables for binary logistic regression y1 <- ifelse(swiss$FertilityThanks to the help of a stackoverflow user, I now know that the order of aes-parameters matters in case you have dodged positioning of geoms on a discrete scale. An example: I use following code in my function

`ggplot(finalodds, aes(y=OR, x=xpos, colour=grp, alpha=pa))`

to apply different colours to each model and setting an alpha-level for geoms depending on the p-level. If the alpha-aes would appear before the colour-aes, the order of lines representing a model may be different for different x-values (see stackoverflow example).Another more appealing example (not reproducable, since it relies on data from a current research project):

And finally an example where p-levels are represented by different shapes and non-significant odds have a lower alpha-level:

This function and an equivalent for linear models will be included in the next update of my sjPlot package.

Toleave a commentfor the author, please follow the link and comment on their blog:Strenge Jacke! » R.

R-bloggers.com offersdaily e-mail updatesabout R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.