ggca {ggfacto}R Documentation

Readable and Interactive graph for simple correspondence analysis

Description

A readable, complete and beautiful graph for simple correspondence analysis made with FactoMineR::CA. Interactive tooltips, appearing when hovering on points with mouse, allow to keep in mind all the content of the table while reading the graph. Since it is made in the spirit of ggplot2, it is possible to change theme or add another plot elements with +. Then, interactive tooltips won't appear until you pass the result through ggi.

Usage

ggca(
  res.ca = res.ca,
  axes = c(1, 2),
  show_sup = FALSE,
  xlim,
  ylim,
  out_lims_move = FALSE,
  type = c("points", "text", "labels"),
  text_repel = FALSE,
  uppercase = "col",
  tooltips = c("row", "col"),
  rowtips_subtitle = "Row pct",
  coltips_subtitle = "Column pct",
  rowcolor_numbers = 0,
  colcolor_numbers = 0,
  cleannames = TRUE,
  filter = "",
  title,
  text_size = 3.5,
  dist_labels = c("auto", 0.12),
  right_margin = 0,
  size_scale_max = 8,
  use_theme = TRUE
)

Arguments

res.ca

An object created with FactoMineR::CA.

axes

The axes to print, as a numeric vector of length 2.

show_sup

When TRUE show supplementary rows and cols.

xlim, ylim

Horizontal and vertical axes limits, as double vectors of length 2.

out_lims_move

When TRUE, the points out of xlim or ylim are not removed, but moved at the edges of the graph.

type

Determines the way the two variables of the table are printed.

  • "points" : colored points with text legends

  • "text" : colored text

  • "labels" : colored labels

text_repel

When TRUE the graph is not interactive anymore, but the resulting image is better to print because points and labels don't overlaps. It uses ggrepel::geom_text_repel.

uppercase

Print "row" var or "col" var labels with uppercase.

tooltips

Choose the content of interactive tooltips at mouse hover : "col" for the table of columns percentages, "row" for line percentages, default to c("row", "col") for both.

rowtips_subtitle, coltips_subtitle

The subtitles used before the table in interactive tooltips.

rowcolor_numbers, colcolor_numbers

If row var or col var levels are prefixed with numbers(ex. : "1-" ), the number of digits to use to create classes that will be used to add colors to points.

cleannames

Set to TRUE to clean levels names, by removing prefix numbers like "1-", and text in parentheses.

filter

Regex patterns to discard levels of row or col variables.

title

The title of the graph.

text_size

Size of text.

dist_labels

When type = "points", the distance of text and labels from points.

right_margin

A margin at the right, in cm. Useful to read tooltips over points placed at the right of the graph without formatting problems.

size_scale_max

Size of points.

use_theme

By default, a specific ggplot2 theme is used. Set to FALSE to customize your own theme.

Value

A ggplot object to be printed in the 'RStudio' Plots pane. Possibility to add other gg objects with +. Sending the result through ggi will draw the interactive graph in the Viewer pane using ggiraph.

Examples

# Make the correspondence analysis :

tabs <- table(forcats::gss_cat$race, forcats::gss_cat$marital)[-4,]
# 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 marital : correspondence analysis",
                 tooltips = c("row", "col"))
ggi(graph.ca) #to make the plot interactive

# Image plot :
ggca(res.ca,
     title = "Race by marical : correspondence analysis",
     text_repel = TRUE)
     

[Package ggfacto version 0.3.0 Index]