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$Fertility
Thanks 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).
This function and an equivalent for linear models will be included in the next update of my sjPlot package.