{"id":13857412,"url":"https://github.com/graysonwhite/gglm","last_synced_at":"2025-04-09T06:09:32.510Z","repository":{"id":39492402,"uuid":"283051923","full_name":"graysonwhite/gglm","owner":"graysonwhite","description":"Grammar of Graphics for Linear Model Diagnostic Plots","archived":false,"fork":false,"pushed_at":"2025-03-28T15:13:41.000Z","size":8298,"stargazers_count":81,"open_issues_count":2,"forks_count":3,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-28T16:24:50.917Z","etag":null,"topics":["diagnostic-plots","grammar-of-graphics","linear-model-diagnostics","r"],"latest_commit_sha":null,"homepage":"https://graysonwhite.com/gglm/","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/graysonwhite.png","metadata":{"files":{"readme":"README.Rmd","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2020-07-28T00:27:57.000Z","updated_at":"2025-03-28T16:13:34.000Z","dependencies_parsed_at":"2023-01-21T02:03:37.562Z","dependency_job_id":"a789fada-92b2-4ea8-bdef-8e454a24b8bb","html_url":"https://github.com/graysonwhite/gglm","commit_stats":{"total_commits":80,"total_committers":1,"mean_commits":80.0,"dds":0.0,"last_synced_commit":"5b8c00749755049ef01b7ea80cd4c3f88a087d6d"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/graysonwhite%2Fgglm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/graysonwhite%2Fgglm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/graysonwhite%2Fgglm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/graysonwhite%2Fgglm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/graysonwhite","download_url":"https://codeload.github.com/graysonwhite/gglm/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247987285,"owners_count":21028895,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["diagnostic-plots","grammar-of-graphics","linear-model-diagnostics","r"],"created_at":"2024-08-05T03:01:36.220Z","updated_at":"2025-04-09T06:09:32.485Z","avatar_url":"https://github.com/graysonwhite.png","language":"HTML","funding_links":[],"categories":["R","Data and models"],"sub_categories":[],"readme":"---\noutput: github_document\n---\n\n```{r, include = F}\nknitr::opts_chunk$set(\n  fig.path = \"man/figures/\"\n)\n```\n\n\n\u003c!-- badges: start --\u003e\n[![CRAN status](https://www.r-pkg.org/badges/version/gglm)](https://cran.r-project.org/package=gglm)\n[![R-CMD-check](https://github.com/graysonwhite/gglm/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/graysonwhite/gglm/actions/workflows/R-CMD-check.yaml)\n\u003c!-- badges: end --\u003e\n\n# gglm \u003cimg src=\"https://github.com/graysonwhite/gglm/blob/master/figs/gglm.gif?raw=true\" align=\"right\" width=125 /\u003e\n\n## Overview\n\n`gglm`, The Grammar of Graphics for Linear Model Diagnostics, is an R package and [official `ggplot2` extension](https://exts.ggplot2.tidyverse.org/gallery/) that creates beautiful diagnostic plots using `ggplot2` for a variety of model objects. These diagnostic plots are easy to use and adhere to the Grammar of Graphics. The purpose of this package is to provide a sensible alternative to using the base-R `plot()` function to produce diagnostic plots for model objects. Currently, `gglm` supports all model objects that are supported by `broom::augment()`, `broom.mixed::augment()`, or `ggplot2::fortify()`. For example, objects that are outputted from `stats::lm()`, `lme4::lmer()`, `brms::brm()`, and many other common modeling functions will work with `gglm`. The function `gglm::list_model_classes()` provides a full list of model classes supported by `gglm`. \n\n## Installation \n\n`gglm` can be installed from CRAN:\n```{r eval = FALSE}\ninstall.packages(\"gglm\")\n```\n\nOr, the developmental version of `gglm` can be installed from GitHub:\n```{r eval = FALSE}\ndevtools::install_github(\"graysonwhite/gglm\")\n```\n\n## Examples\n\n`gglm` has two main types of functions. First, the `gglm()` function is used for quickly creating the four main diagnostic plots, and behaves similarly to how `plot()` works on an `lm` type object. Second, the `stat_*()` functions are used to produce diagnostic plots by creating `ggplot2` layers. These layers allow for plotting of particular model diagnostic plots within the `ggplot2` framework. \n\n### Example 1: Quickly creating the four diagnostic plots with `gglm()`\n\nConsider a simple linear model used to predict miles per gallon with weight. We can fit this model with `lm()`, and then diagnose it easily by using `gglm()`.\n```{r, message=F}\nlibrary(gglm) # Load gglm\n\nmodel \u003c- lm(mpg ~ wt, data = mtcars) # Fit the simple linear model\n\ngglm(model) # Plot the four main diagnostic plots\n```\n\nNow, one may be interested in a more complicated model, such as a mixed model with a varying intercept on `cyl`, fit with the `lme4` package. Luckily, `gglm` accommodates a variety of models and modeling packages, so the diagnostic plots for the mixed model can be created in the same way as they were for the simple linear model. \n```{r, message=F}\nlibrary(lme4) # Load lme4 to fit the mixed model\n\nmixed_model \u003c- lmer(mpg ~ wt + (1 | cyl), data = mtcars) # Fit the mixed model\n\ngglm(mixed_model) # Plot the four main diagnostic plots.\n```\n\n### Example 2: Using the Grammar of Graphics with the `stat_*()` functions\n\n`gglm` also provides functionality to stay within the Grammar of Graphics by providing functions that can be used as `ggplot2` layers. An example of one of these functions is the `stat_fitted_resid()` function. With this function, we can take a closer look at just the fitted vs. residual plot from the mixed model fit in Example 1.\n\n```{r}\nggplot(data = mixed_model) +\n  stat_fitted_resid()\n```\n\nAfter taking a closer look, we may want to clean up the look of the plot for a presentation or a project. This can be done by adding other layers from `ggplot2` to the plot. Note that any `ggplot2` layers can be added on to any of the `stat_*()` functions provided by `gglm`. \n\n```{r}\nggplot(data = mixed_model) +\n  stat_fitted_resid(alpha = 1) + \n  theme_bw() + # add a clean theme \n  labs(title = \"Residual vs fitted values for the mixed model\") + # change the title\n  theme(plot.title = element_text(hjust = 0.5)) # center the title\n```\n\nWow! What a beautiful and production-ready diagnostic plot!\n\n## Functions\n\n### For quick and easy plotting\n\n`gglm()` plots the four default diagnostic plots when supplied a model object (this is similar to `plot.lm()` in the case of an object generated by `lm()`). Note that can `gglm()` take many types of model object classes as its input, and possible model object classes can be seen with `list_model_classes()`\n\n### Following the Grammar of Graphics\n\n`stat_normal_qq()`, `stat_fitted_resid()`, `stat_resid_hist()`, `stat_scale_location()`, `stat_cooks_leverage()`, `stat_cooks_obs()`, and `stat_resid_leverage()` all are `ggplot2` layers used to create individual diagnostic plots. To use these, follow Example 2. \n\n### Other functions\n\n`list_model_classes()` lists the model classes compatible with `gglm`. \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgraysonwhite%2Fgglm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgraysonwhite%2Fgglm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgraysonwhite%2Fgglm/lists"}