{"id":14068141,"url":"https://github.com/schloerke/autocogs","last_synced_at":"2025-03-20T01:31:08.428Z","repository":{"id":51302094,"uuid":"91714580","full_name":"schloerke/autocogs","owner":"schloerke","description":null,"archived":false,"fork":false,"pushed_at":"2021-05-29T17:08:23.000Z","size":1363,"stargazers_count":6,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-09-22T07:46:17.760Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/schloerke.png","metadata":{"files":{"readme":"README.Rmd","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-05-18T16:20:57.000Z","updated_at":"2022-05-02T22:53:09.000Z","dependencies_parsed_at":"2022-09-17T18:51:55.957Z","dependency_job_id":null,"html_url":"https://github.com/schloerke/autocogs","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/schloerke%2Fautocogs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/schloerke%2Fautocogs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/schloerke%2Fautocogs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/schloerke%2Fautocogs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/schloerke","download_url":"https://codeload.github.com/schloerke/autocogs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219865974,"owners_count":16555917,"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":[],"created_at":"2024-08-13T07:05:58.548Z","updated_at":"2024-10-10T18:34:54.749Z","avatar_url":"https://github.com/schloerke.png","language":"R","readme":"---\noutput:\n  github_document:\n    html_preview: false\n---\n\n\u003c!-- rmarkdown::render(\"README.Rmd\") --\u003e\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n```{r, echo = FALSE}\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  comment = \"#\u003e\",\n  fig.path = file.path(\"man\", \"figures\", \"\"),\n  fig.height = 8,\n  fig.width = 12\n)\n```\n\n# autocogs\n[![Travis-CI Build Status](https://travis-ci.org/schloerke/autocogs.svg?branch=master)](https://travis-ci.org/schloerke/autocogs)\n[![Coverage Status](https://img.shields.io/codecov/c/github/schloerke/autocogs/master.svg)](https://codecov.io/github/schloerke/autocogs?branch=master)\n[![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/autocogs)](https://cran.r-project.org/package=autocogs)\n\n\nCognostics are univariate statistics (or metrics) for a subset of data.  When paired with the underlying data of visualizations, cognostics are a powerful tool for ordering and filtering the visualizations.  `add_panel_cogs()` will automatically append cognostics for each plot player in a given panel column.  The newly appended data can be fed into a [trelliscopejs](https://github.com/hafen/trelliscopejs) widget for easy viewing.\n\n## Installation\n\nYou can install autocogs from github with:\n\n```{r gh-installation, eval = FALSE}\nremotes::install_github(\"schloerke/autocogs\")\n```\n\n## Examples\n\n### Gapminder\n\n```{r explore}\nlibrary(autocogs)\nlibrary(tidyverse)\nlibrary(gapminder)\n# remotes::install_github(\"hafen/trelliscopejs\")\n# remotes::install_github(\"schloerke/trelliscopejs@autocogs\")\nlibrary(trelliscopejs)\n\n# Explore\np \u003c-\n  ggplot(gapminder, aes(year, lifeExp)) +\n  geom_line(aes(group = country)) +\n  geom_smooth(method = \"lm\", formula = y ~ x)\np\n```\n\nLooking at the plot above, most countries follow a linear trend:  As the year increases, life expectancy goes up.  A few countries do not follow a linear trend.\n\nIn the examples below, we will extract cognostics to aid in exploring the countries whose life expectancy is not linear.\n\n#### `trelliscopejs::facet_trelliscope()`\n\n```{r facet_trelliscope}\nggplot(gapminder, aes(year, lifeExp)) +\n  geom_smooth(method = \"lm\", formula = y ~ x) +\n  geom_line() +\n  trelliscopejs::facet_trelliscope(\n    ~ country + continent,\n    nrow = 3, ncol = 6,\n    self_contained = TRUE,\n    auto_cog = TRUE,\n    state = list(\n      # set the state to display the country, continent, and R^2 value\n      #   sorted by ascending R^2 value\n      sort = list(trelliscopejs::sort_spec(\"_lm_r2\")),\n      labels = c(\"country\", \"continent\", \"_lm_r2\")\n    ),\n    path = \"readme-figs/facet\"\n  )\n# (screen shot of trelliscopejs widget)\n```\n\n#### `trelliscopejs::trelliscope()`\n\nThis is a full, start to finish example how automatic cognostics could be inserted into a data exploration workflow.\n\n```{r gapminder}\n# Find a consistent y range\ny_range \u003c- range(gapminder$lifeExp)\n\n## # Set up data and panel column\ngapminder %\u003e%\n  group_by(country, continent) %\u003e%\n  # nest the data according to the country and continent\n  nest() %\u003e%\n  mutate(\n    # create a column of plots with a\n    # * line\n    # * linear model\n    panel = lapply(data, function(dt) {\n      ggplot(dt, aes(year, lifeExp)) +\n        geom_smooth(method = \"lm\", formula = y ~ x) +\n        geom_line() +\n        ylim(y_range[1], y_range[2])\n    })\n  ) %\u003e%\n  print() -\u003e\ngap_data\n\n# Double check the plot worked...\n# Look at the first panel (ggplot2 plot) of Afghanistan\ngap_data$panel[[1]]\n\n#!!!!!!!!!!\n# Add cognostic information given the panel column plots\n#!!!!!!!!!!\ngap_data %\u003e%\n  autocogs::add_panel_cogs() %\u003e%\n  ungroup() %\u003e%\n  # double check it was added\n  print(width = 100) -\u003e\nfull_gap_data\n\n# Display the panel and cognostics in a trelliscopejs widget\ntrelliscopejs::trelliscope(\n  full_gap_data, \"gapminder life expectancy\",\n  panel_col = \"panel\",\n  ncol = 6, nrow = 3,\n  auto_cog = FALSE,\n  self_contained = TRUE,\n  state = list(\n    # sort by ascending R^2 value (percent explained by linear model)\n    sort = list(trelliscopejs::sort_spec(\"_lm_r2\")),\n    # display the country, continent, and R^2 value\n    labels = c(\"country\", \"continent\", \"_lm_r2\")\n  ),\n  path = \"readme-figs/manually\"\n)\n# (screen shot of trelliscopejs widget)\n```\n\n### Custom Cognostics\n\n* `add_cog_group()` to add a custom cognostics group.\n* `add_layer_cogs()` to call which cognostics groups should be executed for a given plot layer.\n\nUsing existing code from the `autocogs` package, we will add the univariate continuous cognostics group.\n\n```r\nadd_cog_group(\n  \"univariate_continuous\",\n  field_info(\"x\", \"continuous\"),\n  \"univariate metrics for continuous data\",\n  function(x, ...) {\n    x_range \u003c- range(x, na.rm = TRUE)\n    list(\n      min = cog_desc(x_range[1], \"minimum of non NA data\"),\n      max = cog_desc(x_range[2], \"maximum of non NA data\"),\n      mean = cog_desc(mean(x, na.rm = TRUE), \"mean of non NA data\"),\n      median = cog_desc(median(x, na.rm = TRUE), \"median of non NA data\"),\n      var = cog_desc(var(x, na.rm = TRUE), \"variance of non NA data\")\n    )\n  }\n)\n```\n\nWe can then call the `'univariate_continuous'` cognostics group whenever a `geom_rug` layer is added in a ggplot2 plot object using the code below.\n\n```r\nadd_layer_cogs(\n  # load_all(); p \u003c- qplot(x = 1, y = Sepal.Length, data = iris, geom = \"boxplot\"); plot_cogs(p)\n  \"geom_boxplot\",\n  \"boxplot plot\",\n  cog_group_df(\n    \"univariate_continuous\", \"y\", \"_y\",\n    \"boxplot\", \"y\", \"_boxplot\",\n    \"univariate_counts\", \"y\", \"_n\"\n  )\n)\n```\n\n\u003c!-- ## Connecting other plot objects\n\nThere are  --\u003e\n","funding_links":[],"categories":["R"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fschloerke%2Fautocogs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fschloerke%2Fautocogs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fschloerke%2Fautocogs/lists"}