{"id":13711266,"url":"https://github.com/BriceNocenti/ggfacto","last_synced_at":"2025-05-06T20:32:41.248Z","repository":{"id":56934479,"uuid":"344521254","full_name":"BriceNocenti/ggfacto","owner":"BriceNocenti","description":"Interactive Graphs for Correspondence Analysis","archived":false,"fork":false,"pushed_at":"2024-03-17T15:50:50.000Z","size":2306,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-05-29T11:28:21.077Z","etag":null,"topics":["r"],"latest_commit_sha":null,"homepage":"","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BriceNocenti.png","metadata":{"files":{"readme":"README.Rmd","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-03-04T15:30:39.000Z","updated_at":"2024-02-20T07:45:19.000Z","dependencies_parsed_at":"2024-05-29T01:47:27.431Z","dependency_job_id":"a12cf09e-24b7-4b5a-83e7-33e4761d6062","html_url":"https://github.com/BriceNocenti/ggfacto","commit_stats":{"total_commits":31,"total_committers":2,"mean_commits":15.5,"dds":"0.22580645161290325","last_synced_commit":"aeb19fcf1abf716a0a183977ccf8e1ceb31c0cb0"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BriceNocenti%2Fggfacto","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BriceNocenti%2Fggfacto/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BriceNocenti%2Fggfacto/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BriceNocenti%2Fggfacto/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BriceNocenti","download_url":"https://codeload.github.com/BriceNocenti/ggfacto/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224528385,"owners_count":17326356,"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":["r"],"created_at":"2024-08-02T23:01:06.370Z","updated_at":"2024-11-13T21:31:44.294Z","avatar_url":"https://github.com/BriceNocenti.png","language":"R","funding_links":[],"categories":["Plot layers"],"sub_categories":[],"readme":"---\noutput: \n  github_document\n---\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n```{r, include = FALSE}\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  comment = \"#\u003e\",\n  fig.path = \"man/figures/README-\",\n  out.width = \"100%\"\n)\n```\n\n# ggfacto\n\n\u003c!-- badges: start --\u003e\n\n[![R-CMD-check](https://github.com/BriceNocenti/ggfacto/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/BriceNocenti/ggfacto/actions/workflows/R-CMD-check.yaml)\n\n\u003c!-- badges: end --\u003e \n\nReadable, complete and pretty graphs for correspondence analysis made with [FactoMineR](http://factominer.free.fr/). Many can be rendered as interactive html plots, showing useful informations at mouse hover. The interest is not mainly visual but statistical : it helps the reader to keep in mind the data contained in the cross-table or Burt table while reading correspondence analysis, thus preventing overinterpretation. Graphs are made with [ggplot2](https://ggplot2.tidyverse.org/), which means that you can use the `+` syntax to manually add as many graphical pieces you want, or change theme elements.\n\n## Installation\n\nYou can install ggfacto from `CRAN`:\n\n``` r \ninstall.packages(\"ggfacto\")\n```\n\nOr install the development version from `github`:\n\n``` r\n# install.packages(\"devtools\")\ndevtools::install_github(\"BriceNocenti/ggfacto\")\n```\n\n## Interactive plot from multiple correspondence analysis (MCA)\nMake the MCA (using a wrapper function around `FactoMineR:MCA`) :\n``` {r, results = \"hide\"}\nlibrary(ggfacto)\n\ndata(tea, package = \"FactoMineR\")\nres.mca \u003c- MCA2(tea, active_vars = 1:18)\n```\n\nMake the plot (as a ggplot2 object) and add a supplementary variable (`\"SPC\"`) :\n``` r\ngraph_mca \u003c- ggmca(res.mca, tea, sup_vars = \"SPC\", profiles = TRUE, text_repel = TRUE)\n```\n\nUse `text_repel = TRUE` to avoid overlapping of text, and obtain a more readable image (be careful that, if the plot is overloaded, labels can be far away from their original location). \n\nUse `profiles = TRUE` to draw the graph of individuals : one point is added for each profile of answers.\n\nTurn the plot interactive : \n``` r\nggi(graph_mca)\n```\n\n![](readme_plot.png)\n\n### See the crosstables of active variables directly on the plot\nIt is possible to print all crosstables between active variables (burt table) into the interactive tooltips. Spread from mean are colored and, usually, points near the middle will have less colors, and points at the edges will have plenty. It may takes time to print, but really helps to interpret the MCA in close proximity with the underlying data.\n``` r\nggmca(res.mca, tea, sup_vars = \"SPC\", active_tables = \"active\", \n      ylim = c(NA, 1.2), text_repel = TRUE) %\u003e%\n  ggi()\n```\n\n### See the distribution of active variables for each level of a supplementary variable\n``` r\nggmca(res.mca, tea, sup_vars = \"SPC\", active_tables = \"sup\", \n      ylim = c(NA, 1.2), text_repel = TRUE) %\u003e%\n  ggi()\n```\n\n### Concentration ellipses for each levels of a supplementary variable\n``` {r, fig.width = 6, fig.height = 6, results = \"hide\"}\nggmca(res.mca, tea, sup_vars = \"SPC\", ylim = c(NA, 1.2), ellipses = 0.95, text_repel = TRUE, profiles = TRUE)\n```\n\n### Graph of profiles of answer for each levels of a supplementary variable (with median ellipses containing half the population)\n``` {r, fig.width = 6, fig.height = 6, results = \"hide\"}\nggmca(res.mca, tea, sup_vars = \"SPC\", ylim = c(NA, 1.2), type = \"facets\", ellipses = 0.5, profiles = TRUE)\n```\n\n\u003c!-- ## Table to help to interpret MCA --\u003e\n\u003c!-- ``` {r} --\u003e\n\u003c!-- mca_interpret(res.mca, 1:3) --\u003e\n\u003c!-- ``` --\u003e\n\n## Simple correspondence analysis (CA)\nMake the correspondence analysis :\n``` r\ntabs \u003c- tabxplor::tab_plain(forcats::gss_cat, race, marital, df = TRUE)\nres.ca \u003c- FactoMineR::CA(tabs, graph = FALSE)\n``` \n\n```{r, echo = FALSE}\ntabs \u003c- table(forcats::gss_cat$race, forcats::gss_cat$marital)[-4,]\nres.ca \u003c- FactoMineR::CA(tabs, graph = FALSE)\n```\n\nInteractive plot :\n``` r\ngraph.ca \u003c- ggca(res.ca,\n                 title = \"Race by marical : correspondence analysis\",\n                 tooltips = c(\"row\", \"col\"))\nggi(graph.ca)\n```\n\nImage plot (with `text_repel` to avoid overlapping of labels) :\n``` {r}\nggca(res.ca,\n     title = \"Race by marical : correspondence analysis\",\n     text_repel = TRUE, dist_labels = 0.02)\n```\n\n## Personnalize plots\n\nStep-by-step functions can be used to create a database with all the necessary data, modify it, then use it to draw the plot:\n``` {r, fig.width = 6, fig.height = 6, results = \"hide\", message = FALSE}\nlibrary(dplyr)\nlibrary(ggplot2)\n\nplot_data \u003c- ggmca_data(res.mca, tea, sup_vars = \"SPC\")\n\nplot_data$vars_data \u003c- plot_data$vars_data %\u003e% \n  filter(!lvs %in% c(\"other worker\", \"non-worker\"))\n\nggmca_plot(plot_data, ylim = c(NA, 1.2), text_repel = TRUE)\n```\n\nThe plot can always be modified using the `ggplot2` `+` operator : \n``` {r, fig.width = 6, fig.height = 6, results = \"hide\"}\nggmca_plot(plot_data, ylim = c(NA, 1.2)) +\n  labs(title = \"Multiple correspondence analysis\") +\n  theme(axis.line = element_line(linetype = \"solid\") )\n\n```\nYou can then pass to plot to `ggi()` to make it interactive.\n\nSet `use_theme = FALSE` to use you own ggplot2 theme :\n``` {r, fig.width = 6, fig.height = 6}\nggmca_plot(plot_data, ylim = c(NA, 1.2), use_theme = FALSE) +\n  theme_classic()\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FBriceNocenti%2Fggfacto","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FBriceNocenti%2Fggfacto","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FBriceNocenti%2Fggfacto/lists"}