ggfacto

Interactive Graphs for Correspondence Analysis

https://github.com/bricenocenti/ggfacto

Science Score: 26.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (15.5%) to scientific vocabulary

Keywords

r
Last synced: 11 months ago · JSON representation

Repository

Interactive Graphs for Correspondence Analysis

Basic Info
  • Host: GitHub
  • Owner: BriceNocenti
  • License: gpl-3.0
  • Language: R
  • Default Branch: main
  • Homepage:
  • Size: 2.21 MB
Statistics
  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • Open Issues: 1
  • Releases: 3
Topics
r
Created over 5 years ago · Last pushed almost 2 years ago
Metadata Files
Readme Changelog License

README.Rmd

---
output: 
  github_document
---



```{r, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)
```

# ggfacto



[![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)

 

Readable, 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.

## Installation

You can install ggfacto from `CRAN`:

``` r 
install.packages("ggfacto")
```

Or install the development version from `github`:

``` r
# install.packages("devtools")
devtools::install_github("BriceNocenti/ggfacto")
```

## Interactive plot from multiple correspondence analysis (MCA)
Make the MCA (using a wrapper function around `FactoMineR:MCA`) :
``` {r, results = "hide"}
library(ggfacto)

data(tea, package = "FactoMineR")
res.mca <- MCA2(tea, active_vars = 1:18)
```

Make the plot (as a ggplot2 object) and add a supplementary variable (`"SPC"`) :
``` r
graph_mca <- ggmca(res.mca, tea, sup_vars = "SPC", profiles = TRUE, text_repel = TRUE)
```

Use `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). 

Use `profiles = TRUE` to draw the graph of individuals : one point is added for each profile of answers.

Turn the plot interactive : 
``` r
ggi(graph_mca)
```

![](readme_plot.png)

### See the crosstables of active variables directly on the plot
It 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.
``` r
ggmca(res.mca, tea, sup_vars = "SPC", active_tables = "active", 
      ylim = c(NA, 1.2), text_repel = TRUE) %>%
  ggi()
```

### See the distribution of active variables for each level of a supplementary variable
``` r
ggmca(res.mca, tea, sup_vars = "SPC", active_tables = "sup", 
      ylim = c(NA, 1.2), text_repel = TRUE) %>%
  ggi()
```

### Concentration ellipses for each levels of a supplementary variable
``` {r, fig.width = 6, fig.height = 6, results = "hide"}
ggmca(res.mca, tea, sup_vars = "SPC", ylim = c(NA, 1.2), ellipses = 0.95, text_repel = TRUE, profiles = TRUE)
```

### Graph of profiles of answer for each levels of a supplementary variable (with median ellipses containing half the population)
``` {r, fig.width = 6, fig.height = 6, results = "hide"}
ggmca(res.mca, tea, sup_vars = "SPC", ylim = c(NA, 1.2), type = "facets", ellipses = 0.5, profiles = TRUE)
```






## Simple correspondence analysis (CA)
Make the correspondence analysis :
``` r
tabs <- tabxplor::tab_plain(forcats::gss_cat, race, marital, df = TRUE)
res.ca <- FactoMineR::CA(tabs, graph = FALSE)
``` 

```{r, echo = FALSE}
tabs <- table(forcats::gss_cat$race, forcats::gss_cat$marital)[-4,]
res.ca <- FactoMineR::CA(tabs, graph = FALSE)
```

Interactive plot :
``` r
graph.ca <- ggca(res.ca,
                 title = "Race by marical : correspondence analysis",
                 tooltips = c("row", "col"))
ggi(graph.ca)
```

Image plot (with `text_repel` to avoid overlapping of labels) :
``` {r}
ggca(res.ca,
     title = "Race by marical : correspondence analysis",
     text_repel = TRUE, dist_labels = 0.02)
```

## Personnalize plots

Step-by-step functions can be used to create a database with all the necessary data, modify it, then use it to draw the plot:
``` {r, fig.width = 6, fig.height = 6, results = "hide", message = FALSE}
library(dplyr)
library(ggplot2)

plot_data <- ggmca_data(res.mca, tea, sup_vars = "SPC")

plot_data$vars_data <- plot_data$vars_data %>% 
  filter(!lvs %in% c("other worker", "non-worker"))

ggmca_plot(plot_data, ylim = c(NA, 1.2), text_repel = TRUE)
```

The plot can always be modified using the `ggplot2` `+` operator : 
``` {r, fig.width = 6, fig.height = 6, results = "hide"}
ggmca_plot(plot_data, ylim = c(NA, 1.2)) +
  labs(title = "Multiple correspondence analysis") +
  theme(axis.line = element_line(linetype = "solid") )

```
You can then pass to plot to `ggi()` to make it interactive.

Set `use_theme = FALSE` to use you own ggplot2 theme :
``` {r, fig.width = 6, fig.height = 6}
ggmca_plot(plot_data, ylim = c(NA, 1.2), use_theme = FALSE) +
  theme_classic()
```

Owner

  • Login: BriceNocenti
  • Kind: user

GitHub Events

Total
Last Year

Committers

Last synced: over 2 years ago

All Time
  • Total Commits: 31
  • Total Committers: 2
  • Avg Commits per committer: 15.5
  • Development Distribution Score (DDS): 0.226
Past Year
  • Commits: 0
  • Committers: 0
  • Avg Commits per committer: 0.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
BriceNocenti b****i@g****m 24
BriceNocenti 7****i 7

Issues and Pull Requests

Last synced: 11 months ago

All Time
  • Total issues: 1
  • Total pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Total issue authors: 1
  • Total pull request authors: 0
  • Average comments per issue: 0.0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 1
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 1
  • Pull request authors: 0
  • Average comments per issue: 0.0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • davidgohel (1)
Pull Request Authors
Top Labels
Issue Labels
Pull Request Labels

Packages

  • Total packages: 3
  • Total downloads:
    • cran 217 last-month
  • Total dependent packages: 0
    (may contain duplicates)
  • Total dependent repositories: 0
    (may contain duplicates)
  • Total versions: 11
  • Total maintainers: 1
proxy.golang.org: github.com/bricenocenti/ggfacto
  • Versions: 3
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent packages count: 6.5%
Average: 6.7%
Dependent repos count: 6.9%
Last synced: 11 months ago
proxy.golang.org: github.com/BriceNocenti/ggfacto
  • Versions: 3
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent packages count: 6.5%
Average: 6.7%
Dependent repos count: 6.9%
Last synced: 11 months ago
cran.r-project.org: ggfacto

Graphs for Correspondence Analysis

  • Versions: 5
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 217 Last month
Rankings
Forks count: 28.8%
Dependent packages count: 29.8%
Stargazers count: 35.2%
Dependent repos count: 35.5%
Average: 43.8%
Downloads: 89.7%
Maintainers (1)
Last synced: 11 months ago

Dependencies

DESCRIPTION cran
  • FactoMineR >= 2.0.0 imports
  • dplyr >= 1.0.0 imports
  • forcats >= 0.5.0 imports
  • ggiraph >= 0.8.2 imports
  • ggplot2 >= 3.0.0 imports
  • ggrepel >= 0.9.0 imports
  • grDevices >= 4.0.0 imports
  • gridExtra >= 2.0 imports
  • htmlwidgets >= 1.4.0 imports
  • magrittr >= 1.5.0 imports
  • purrr >= 0.3.0 imports
  • rlang >= 0.4.0 imports
  • stats >= 4.0.0 imports
  • stringi >= 1.4.6 imports
  • stringr >= 1.4.0 imports
  • tabxplor >= 1.0.0 imports
  • tibble >= 3.0.0 imports
  • tidyr >= 1.0.0 imports
  • tidyselect >= 1.1.0 imports
  • vctrs >= 0.3.0 imports
  • widgetframe >= 0.3.0 imports
  • withr >= 2.0.0 imports
  • finalfit >= 1.0.0 suggests
  • kableExtra >= 1.3.0 suggests
.github/workflows/R-CMD-check.yaml actions
  • actions/checkout v3 composite
  • r-lib/actions/check-r-package v2 composite
  • r-lib/actions/setup-pandoc v2 composite
  • r-lib/actions/setup-r v2 composite
  • r-lib/actions/setup-r-dependencies v2 composite