MyNixOS website logo
Description

Graphs for Correspondence Analysis.

Readable, complete and pretty graphs for correspondence analysis made with 'FactoMineR'. They 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 the correspondence analysis, thus preventing over-interpretation. Most graphs are made with 'ggplot2', which means that you can use the + syntax to manually add as many graphical pieces you want, or change theme elements. 3D graphs are made with 'plotly'.

ggfacto

R-CMD-check

Readable, complete and pretty graphs for correspondence analysis made with FactoMineR. 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, 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:

install.packages("ggfacto")

Or install the development version from github:

# 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) :

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") :

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 :

ggi(graph_mca)

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.

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

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

ggmca(res.mca, tea, sup_vars = "SPC", ylim = c(NA, 1.2), ellipses = 0.95, text_repel = TRUE, profiles = TRUE)
#> colors based on the following categories (rename with colornames_recode): 'SPC_employee', 'SPC_middle', 'SPC_non-worker', 'SPC_other worker', 'SPC_senior', 'SPC_student', 'SPC_workman'

Graph of profiles of answer for each levels of a supplementary variable (with median ellipses containing half the population)

ggmca(res.mca, tea, sup_vars = "SPC", ylim = c(NA, 1.2), type = "facets", ellipses = 0.5, profiles = TRUE)
#> colors based on the following categories (rename with colornames_recode): 'SPC_employee', 'SPC_middle', 'SPC_non-worker', 'SPC_other worker', 'SPC_senior', 'SPC_student', 'SPC_workman'

Simple correspondence analysis (CA)

Make the correspondence analysis :

tabs <- tabxplor::tab_plain(forcats::gss_cat, race, marital, df = TRUE)
res.ca <- FactoMineR::CA(tabs, graph = FALSE)

Interactive plot :

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) :

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:

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 :

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 :

ggmca_plot(plot_data, ylim = c(NA, 1.2), use_theme = FALSE) +
  theme_classic()
Metadata

Version

0.3.0

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows