Title: | Graphs for Correspondence Analysis |
---|---|
Description: | 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'. |
Authors: | Brice Nocenti [aut, cre] |
Maintainer: | Brice Nocenti <[email protected]> |
License: | GPL (>= 3) |
Version: | 0.3.2 |
Built: | 2024-11-01 06:12:18 UTC |
Source: | https://github.com/bricenocenti/ggfacto |
Benzecri's modified rate of variance
benzecri_mrv(res.mca, fmt = FALSE)
benzecri_mrv(res.mca, fmt = FALSE)
res.mca |
The result of MCA. |
fmt |
By default, the result is given as a numeric vector. Set to 'TRUE' to have
a tabxplor |
A numeric vector (or fmt vector with 'fmt = TRUE').
data(tea, package = "FactoMineR") res.mca <- MCA2(tea, active_vars = 1:18) benzecri_mrv(res.mca)
data(tea, package = "FactoMineR") res.mca <- MCA2(tea, active_vars = 1:18) benzecri_mrv(res.mca)
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
.
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 )
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 )
res.ca |
An object created with |
axes |
The axes to print, as a numeric vector of length 2. |
show_sup |
When |
xlim , ylim
|
Horizontal and vertical axes limits, as double vectors of length 2. |
out_lims_move |
When |
type |
Determines the way the two variables of the table are printed.
|
text_repel |
When |
uppercase |
Print |
tooltips |
Choose the content of interactive tooltips at mouse hover :
|
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. : |
cleannames |
Set to |
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 |
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 |
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
.
# 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)
# 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)
Pass a MCA plot into a html interactive plot
ggi( plot = ggplot2::last_plot(), width = NULL, height = NULL, keep_ratio = TRUE, savewidget = FALSE, dir = NULL, name = "Plot", replace = FALSE, open = rlang::is_interactive(), iframe = NULL, pixel_width, ... )
ggi( plot = ggplot2::last_plot(), width = NULL, height = NULL, keep_ratio = TRUE, savewidget = FALSE, dir = NULL, name = "Plot", replace = FALSE, open = rlang::is_interactive(), iframe = NULL, pixel_width, ... )
plot |
|
width |
The width in centimeters. Default to printing device's size. |
height |
The height in centimeters. Default to printing device's size. |
keep_ratio |
By default, the height is forced based of the relative
size of the MCA's axes. Set to |
savewidget |
Should the html widget be saved on disk ? |
dir |
If saved as file, the directory in which to save the html widget.
Default to temporary directory. Set global option |
name |
The name of the file to save. |
replace |
Replace file ? By default, number added to find a new name. |
open |
Should the resulting file be opened at once ? |
iframe |
Create an html frame around the plot to ensure fixed
dimensions. Useful when opening the plot in a web browser (but will produce a blank
graph with rmarkdown). This is default behavior with |
pixel_width |
The width in pixels for
|
... |
Additional arguments to pass to |
An html plot.
A readable, complete and beautiful graph for multiple
correspondence analysis made with FactoMineR::MCA
.
Interactive tooltips, appearing when hovering near points with mouse,
allow to keep in mind many important data (tables of active variables,
and additional chosen variables) while reading the graph.
Profiles of answers (from the graph of "individuals") are drawn in the back,
and can be linked to FactoMineR::HCPC
classes.
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
.
Step-by-step functions : use ggmca_data to get the data frames with every
parameter in a MCA printing, then modify, and pass to ggmca_plot
to draw the graph.
ggmca( res.mca, dat, sup_vars, active_tables, tooltip_vars_1lv, tooltip_vars, axes = c(1, 2), axes_names = NULL, axes_reverse = NULL, type = c("text", "labels", "points", "numbers", "facets"), color_groups = "^.{0}", cah_color_groups = "^.+$", keep_levels, discard_levels, cleannames = TRUE, profiles = FALSE, profiles_tooltip_discard = "^Not |^No |^Pas |^Non ", cah, max_profiles = 5000, alpha_profiles = 0.7, color_profiles = TRUE, base_profiles_color = "#aaaaaa", text_repel = FALSE, title, actives_in_bold = NULL, sup_in_italic = FALSE, ellipses = NULL, xlim, ylim, out_lims_move = FALSE, shift_colors = 0, colornames_recode, scale_color_light = material_colors_light(), scale_color_dark = material_colors_dark(), text_size = 3.5, size_scale_max = 4, dist_labels = c("auto", 0.04), right_margin = 0, use_theme = TRUE, get_data = FALSE ) ggmca_data( res.mca, dat, sup_vars, active_tables, tooltip_vars_1lv, tooltip_vars, color_groups = "^.{0}", cah_color_groups = "^.+$", keep_levels, discard_levels, cleannames = TRUE, profiles = FALSE, profiles_tooltip_discard = "^Pas |^Non |^Not |^No ", cah, max_profiles = 5000 ) ggmca_plot( data, axes = c(1, 2), axes_names = NULL, axes_reverse = NULL, type = c("text", "points", "labels", "active_vars_only", "numbers", "facets"), text_repel = FALSE, title, ellipses = NULL, actives_in_bold = NULL, sup_in_italic = FALSE, xlim, ylim, out_lims_move = FALSE, color_profiles = TRUE, base_profiles_color = "#aaaaaa", alpha_profiles = 0.7, shift_colors = 0, colornames_recode, scale_color_light = material_colors_light(), scale_color_dark = material_colors_dark(), text_size = 3.5, size_scale_max = 4, dist_labels = c("auto", 0.04), right_margin = 0, use_theme = TRUE, get_data = FALSE )
ggmca( res.mca, dat, sup_vars, active_tables, tooltip_vars_1lv, tooltip_vars, axes = c(1, 2), axes_names = NULL, axes_reverse = NULL, type = c("text", "labels", "points", "numbers", "facets"), color_groups = "^.{0}", cah_color_groups = "^.+$", keep_levels, discard_levels, cleannames = TRUE, profiles = FALSE, profiles_tooltip_discard = "^Not |^No |^Pas |^Non ", cah, max_profiles = 5000, alpha_profiles = 0.7, color_profiles = TRUE, base_profiles_color = "#aaaaaa", text_repel = FALSE, title, actives_in_bold = NULL, sup_in_italic = FALSE, ellipses = NULL, xlim, ylim, out_lims_move = FALSE, shift_colors = 0, colornames_recode, scale_color_light = material_colors_light(), scale_color_dark = material_colors_dark(), text_size = 3.5, size_scale_max = 4, dist_labels = c("auto", 0.04), right_margin = 0, use_theme = TRUE, get_data = FALSE ) ggmca_data( res.mca, dat, sup_vars, active_tables, tooltip_vars_1lv, tooltip_vars, color_groups = "^.{0}", cah_color_groups = "^.+$", keep_levels, discard_levels, cleannames = TRUE, profiles = FALSE, profiles_tooltip_discard = "^Pas |^Non |^Not |^No ", cah, max_profiles = 5000 ) ggmca_plot( data, axes = c(1, 2), axes_names = NULL, axes_reverse = NULL, type = c("text", "points", "labels", "active_vars_only", "numbers", "facets"), text_repel = FALSE, title, ellipses = NULL, actives_in_bold = NULL, sup_in_italic = FALSE, xlim, ylim, out_lims_move = FALSE, color_profiles = TRUE, base_profiles_color = "#aaaaaa", alpha_profiles = 0.7, shift_colors = 0, colornames_recode, scale_color_light = material_colors_light(), scale_color_dark = material_colors_dark(), text_size = 3.5, size_scale_max = 4, dist_labels = c("auto", 0.04), right_margin = 0, use_theme = TRUE, get_data = FALSE )
res.mca |
An object created with |
dat |
The data in which to find the supplementary variables, etc. |
sup_vars |
A character vectors of supplementary qualitative variables
to print (they don't need to be passed in |
active_tables |
Should colored crosstables be added in interactive tooltips ?
'active_tables = "sup"' crosses each 'sup_vars' with active variables.
'active_tables = "active"' crosses each active_variables with the other ones,
giving results closely related with the burt table used to calculate multiple
correspondance analysis. It may take time to calculate with many variables.
'active_tables = c("active", "sup")' do both. In tooltips, percentages are colored
in blue when spread from mean is positive (over-representations), and in red when
spread from mean is negative (under-representations), like in
|
tooltip_vars_1lv |
A character vectors of variables, whose first level (if character/factor) or weighted_mean (if numeric) will be added at the top of interactive tooltips. |
tooltip_vars |
A character vector of variables (character/factors), whose complete levels will be added at the bottom of interactive tooltips. |
axes |
The axes to print, as a numeric vector of length 2. |
axes_names |
Names of all the axes (not just the two selected ones), as a character vector. |
axes_reverse |
Possibility to reserve the coordinates of the axes by providing a numeric vector : '1' to invert left and right ; '2' to invert up and down ; '1:2' to invert both. |
type |
Determines the way
|
color_groups |
By default, there is one color group for all the levels
of each 'sup_vars'. It is possible to color 'sup_vars' with groups created
upon their levels with |
cah_color_groups |
Color groups for the 'cah' variable (HCPC clusters). |
keep_levels |
A character vector of variables levels to keep : others will be discarded. |
discard_levels |
A character vector of variables levels to discard. |
cleannames |
Set to |
profiles |
When set to |
profiles_tooltip_discard |
A regex pattern to remove useless levels among interactive tooltips for profiles of answers (ex. : levels expressing "no" answers). |
cah |
A HCPC clusters variable made with |
max_profiles |
The maximum number of profiles points to print. Default to 5000. |
alpha_profiles |
The alpha (transparency, between 0 and 1) for profiles of answer. |
color_profiles |
By default, if |
base_profiles_color |
The base color for answers profiles. Default to gray. Set to 'NULL' to discard profiles. With 'color_profiles', set to 'NULL' to discard the non-colored profiles. |
text_repel |
When |
title |
The title of the graph. |
actives_in_bold |
Set to 'TRUE' to set active variables in bold font (and sup variables in plain). |
sup_in_italic |
Set to 'TRUE' to set sup variables in italics. |
ellipses |
Set to a number between 0 and 1 to draw a concentration ellipse for
each level of the first |
xlim , ylim
|
Horizontal and vertical axes limits, as double vectors of length 2. |
out_lims_move |
When |
shift_colors |
Change colors of the |
colornames_recode |
A named character vector with
|
scale_color_light |
A scale color for sup vars points |
scale_color_dark |
A scale color for sup vars texts |
text_size |
Size of text. |
size_scale_max |
Size of points. |
dist_labels |
When |
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. |
use_theme |
By default, a specific |
get_data |
Returns the data frame to create the plot instead of the plot itself. |
data |
A list of data frames made with ggmca_data. |
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
.
A list containing the data frames to pass to ggmca_plot.
A ggplot
object.
ggmca_data()
: get the data frames with all parameters to print a MCA graph
ggmca_plot()
: print MCA graph from data frames with parameters
data(tea, package = "FactoMineR") res.mca <- MCA2(tea, active_vars = 1:18) # Interactive graph for multiple correspondence analysis : res.mca |> ggmca(tea, sup_vars = c("SPC"), ylim = c(NA, 1.2), text_repel = TRUE) |> ggi() #to make the graph interactive # Interactive graph with access to all crosstables between active variables (burt table). # 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 # helps to interpret the MCA in close proximity with the underlying data. res.mca |> ggmca(tea, ylim = c(NA, 1.2), active_tables = "active", text_repel = TRUE) |> ggi() # Graph with colored HCPC clusters cah <- FactoMineR::HCPC(res.mca, nb.clust = 6, graph = FALSE) tea$clust <- cah$data.clust$clust ggmca(res.mca, tea, cah = "clust", profiles = TRUE, text_repel = TRUE) # Concentration ellipses for each levels of a supplementary variable : ggmca(res.mca, tea, sup_vars = "SPC", ylim = c(NA, 1.2), ellipses = 0.5, text_repel = TRUE, profiles = TRUE) # Graph of profiles of answer for each levels of a supplementary variable : ggmca(res.mca, tea, sup_vars = "SPC", ylim = c(NA, 1.2), type = "facets", ellipses = 0.5, profiles = TRUE)
data(tea, package = "FactoMineR") res.mca <- MCA2(tea, active_vars = 1:18) # Interactive graph for multiple correspondence analysis : res.mca |> ggmca(tea, sup_vars = c("SPC"), ylim = c(NA, 1.2), text_repel = TRUE) |> ggi() #to make the graph interactive # Interactive graph with access to all crosstables between active variables (burt table). # 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 # helps to interpret the MCA in close proximity with the underlying data. res.mca |> ggmca(tea, ylim = c(NA, 1.2), active_tables = "active", text_repel = TRUE) |> ggi() # Graph with colored HCPC clusters cah <- FactoMineR::HCPC(res.mca, nb.clust = 6, graph = FALSE) tea$clust <- cah$data.clust$clust ggmca(res.mca, tea, cah = "clust", profiles = TRUE, text_repel = TRUE) # Concentration ellipses for each levels of a supplementary variable : ggmca(res.mca, tea, sup_vars = "SPC", ylim = c(NA, 1.2), ellipses = 0.5, text_repel = TRUE, profiles = TRUE) # Graph of profiles of answer for each levels of a supplementary variable : ggmca(res.mca, tea, sup_vars = "SPC", ylim = c(NA, 1.2), type = "facets", ellipses = 0.5, profiles = TRUE)
Interactive 3D Plot for Multiple Correspondence Analyses (plotly::)
ggmca_3d( res.mca, dat, cah, axes = 1:3, base_zoom = 1, remove_buttons = FALSE, cone_size = 0.15, view = "All", camera_view, aspectratio_from_eig = FALSE, title, ind_name.size = 10, max_point_size = 30, ... )
ggmca_3d( res.mca, dat, cah, axes = 1:3, base_zoom = 1, remove_buttons = FALSE, cone_size = 0.15, view = "All", camera_view, aspectratio_from_eig = FALSE, title, ind_name.size = 10, max_point_size = 30, ... )
res.mca |
An object created with |
dat |
The data in which to find the cah variable, etc. |
cah |
A variable made with |
axes |
The axes to print, as a numeric vector of length 3. |
base_zoom |
The base level of zoom. |
remove_buttons |
Set to TRUE to remove buttons to change view. |
cone_size |
The size of the conic arrow at the end of each axe. |
view |
The starting point of view (in 3D) :
|
camera_view |
Possibility to add a (replace 'view') |
aspectratio_from_eig |
Set to 'TRUE' to modify axes length based on eigenvalues. |
title |
The title of the graph. |
ind_name.size |
The size of the names of individuals. |
max_point_size |
The size of the biggest point. |
... |
Additional arguments to pass to |
A plotly
html interactive 3d (or 2d) graph.
data(tea, package = "FactoMineR") res.mca <- MCA2(tea, active_vars = 1:18) ggmca_3d(res.mca) # 3D graph with colored HCPC clusters (cah) res.mca_3axes <- MCA2(tea, active_vars = 1:18, ncp = 3) cah <- FactoMineR::HCPC(res.mca_3axes, nb.clust = 6, graph = FALSE) tea$clust <- cah$data.clust$clust ggmca_3d(res.mca, dat = tea, cah = "clust")
data(tea, package = "FactoMineR") res.mca <- MCA2(tea, active_vars = 1:18) ggmca_3d(res.mca) # 3D graph with colored HCPC clusters (cah) res.mca_3axes <- MCA2(tea, active_vars = 1:18, ncp = 3) cah <- FactoMineR::HCPC(res.mca_3axes, nb.clust = 6, graph = FALSE) tea$clust <- cah$data.clust$clust ggmca_3d(res.mca, dat = tea, cah = "clust")
This function mostly have an educational value : it shows the
initial dimensions of the Multiple Correspondence Analysis (active variables)
in their initial reference frame. It shows the n dimensional space before the
analysis is done. To see initial dimensions axes in the space built by the
analysis (principal axes), use ggmca_with_base_ref
.
ggmca_initial_dims( res.mca = res.mca, data, proj_just = c(1.5, 2), cleannames = TRUE, keep = NULL )
ggmca_initial_dims( res.mca = res.mca, data, proj_just = c(1.5, 2), cleannames = TRUE, keep = NULL )
res.mca |
An object created with |
data |
The data in which to find the supplementary variables, etc. |
proj_just |
Horizontal justification of text of the coordinates on axes, as a character vector of length 2 (x and y). |
cleannames |
Set to |
keep |
A character vector of the name of active variables to keep. |
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
.
data(tea, package = "FactoMineR") res.mca <- MCA2(tea, active_vars = 1:18) ggmca_initial_dims(res.mca, data = tea)
data(tea, package = "FactoMineR") res.mca <- MCA2(tea, active_vars = 1:18) ggmca_initial_dims(res.mca, data = tea)
This function mostly have an educational value : it shows the
initial dimensions of the Multiple Correspondence Analysis (active variables)
in the space built by the analysis (principal axes). To see initial
dimensions in their initial reference frame, use ggmca_initial_dims
.
ggmca_with_base_ref(res.mca = res.mca, axes = c(1, 2), keep = NULL)
ggmca_with_base_ref(res.mca = res.mca, axes = c(1, 2), keep = NULL)
res.mca |
An object created with |
axes |
The axes to print, as a numeric vector of length 2. |
keep |
A character vector of the name of active variables to keep. |
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
.
data(tea, package = "FactoMineR") res.mca <- MCA2(tea, active_vars = 1:18) ggmca_with_base_ref(res.mca) # It is more readable to select just a few active variables lv2_vars <- dplyr::select(tea[1:18], where(~ nlevels(.) == 2)) |> names() ggmca_with_base_ref(res.mca, keep = lv2_vars) lv3_vars <- dplyr::select(tea[1:18], where(~ nlevels(.) == 3)) |> names() ggmca_with_base_ref(res.mca, keep = lv3_vars) lv4_vars <- dplyr::select(tea[1:18], where(~ nlevels(.) == 4)) |> names() ggmca_with_base_ref(res.mca, keep = lv4_vars) lv6_vars <- dplyr::select(tea[1:18], where(~ nlevels(.) == 6)) |> names() ggmca_with_base_ref(res.mca, keep = lv6_vars)
data(tea, package = "FactoMineR") res.mca <- MCA2(tea, active_vars = 1:18) ggmca_with_base_ref(res.mca) # It is more readable to select just a few active variables lv2_vars <- dplyr::select(tea[1:18], where(~ nlevels(.) == 2)) |> names() ggmca_with_base_ref(res.mca, keep = lv2_vars) lv3_vars <- dplyr::select(tea[1:18], where(~ nlevels(.) == 3)) |> names() ggmca_with_base_ref(res.mca, keep = lv3_vars) lv4_vars <- dplyr::select(tea[1:18], where(~ nlevels(.) == 4)) |> names() ggmca_with_base_ref(res.mca, keep = lv4_vars) lv6_vars <- dplyr::select(tea[1:18], where(~ nlevels(.) == 6)) |> names() ggmca_with_base_ref(res.mca, keep = lv6_vars)
Interactive 3D Plot for Principal Component Analyses (plotly::)
ggpca_3d( res.pca, axes = c(1, 2, 3), princ_axes_print = -3:3, base_axe_n_breaks = 10, ind.size = 4, ind_name.size = 3, title, center = TRUE, var_names_on = "var", base_zoom = 1, remove_buttons = FALSE, cone_size = 0.33, view = "All", type = c("var", "ind", "main_plan", "projections"), camera_view, aspectratio_from_eig = FALSE, always_make_ind_tooltips = FALSE, var_color = "#4D4D4D", max_ind = 500, max_ind_seed )
ggpca_3d( res.pca, axes = c(1, 2, 3), princ_axes_print = -3:3, base_axe_n_breaks = 10, ind.size = 4, ind_name.size = 3, title, center = TRUE, var_names_on = "var", base_zoom = 1, remove_buttons = FALSE, cone_size = 0.33, view = "All", type = c("var", "ind", "main_plan", "projections"), camera_view, aspectratio_from_eig = FALSE, always_make_ind_tooltips = FALSE, var_color = "#4D4D4D", max_ind = 500, max_ind_seed )
res.pca |
The result of |
axes |
The axes to print, as a numeric vector of length 3 (or 2). |
princ_axes_print |
The breaks of the principal axes. |
base_axe_n_breaks |
The number of breaks in initial variables axes. |
ind.size |
The size of the points of individuals. |
ind_name.size |
The size of the names of individuals. |
title |
Plot title. |
center |
By default the plot is centered on the central point. Set to 'FALSE' to center on the origin of all variables (zero coordinates). |
var_names_on |
By default '"var"' the names of variables are drawn upon the initial axes. Set to '"cor"' to draw them upon correlation vectors instead. |
base_zoom |
The base level of zoom. |
remove_buttons |
Set to TRUE to remove buttons to change view. |
cone_size |
The size of the conic arrow at the end of each axe. |
view |
The starting point of view (in 3D) :
|
type |
Which elements of the graph to print, among : #'
|
camera_view |
Possibility to add a (replace 'view') |
aspectratio_from_eig |
Set to 'TRUE' to modify axes length based on eigenvalues. |
always_make_ind_tooltips |
Set to 'TRUE' to add interactive toolips for individuals. |
var_color |
The color of the initial variables/dimensions |
max_ind |
The maximun number of individuals to print. |
max_ind_seed |
The random seed used to sample individuals. |
A plotly
html interactive 2d or 3d graph.
data(mtcars, package = "datasets") mtcars <- mtcars[1:7] |> dplyr::rename(weight = wt) res.pca <- FactoMineR::PCA(mtcars, graph = FALSE) # Variables and individuals ggpca_3d(res.pca) # Circle of correlation 3D ggpca_3d(res.pca, type = c("cor", "cor_sphere"), var_names_on = "cor", base_zoom = 0.6, princ_axes_print = -1:1, view = "All" )
data(mtcars, package = "datasets") mtcars <- mtcars[1:7] |> dplyr::rename(weight = wt) res.pca <- FactoMineR::PCA(mtcars, graph = FALSE) # Variables and individuals ggpca_3d(res.pca) # Circle of correlation 3D ggpca_3d(res.pca, type = c("cor", "cor_sphere"), var_names_on = "cor", base_zoom = 0.6, princ_axes_print = -1:1, view = "All" )
Correlation Circle Plot for Principal Component Analysis
ggpca_cor_circle( res.pca, axes = c(1, 2), proj = FALSE, interactive = TRUE, text_size = 3 )
ggpca_cor_circle( res.pca, axes = c(1, 2), proj = FALSE, interactive = TRUE, text_size = 3 )
res.pca |
The result of |
axes |
The axes to print, as a numeric vector of length 2. |
proj |
Set to 'TRUE' to print projections of vectors over the two axes. |
interactive |
By default an html interactive plot is done. Set to 'FALSE'
to get a normal |
text_size |
Size of the texte. |
A ggplot
.
data(mtcars, package = "datasets") mtcars <- mtcars[1:7] |> dplyr::rename(weight = wt) res.pca <- FactoMineR::PCA(mtcars, graph = FALSE) ggpca_cor_circle(res.pca, interactive = FALSE)
data(mtcars, package = "datasets") mtcars <- mtcars[1:7] |> dplyr::rename(weight = wt) res.pca <- FactoMineR::PCA(mtcars, graph = FALSE) ggpca_cor_circle(res.pca, interactive = FALSE)
Save a plot as image
ggsave2( plot = ggplot2::last_plot(), dir = NULL, name = "Plot", xt = "png", dpi = 600, width = 21, height, scale = 1, replace = FALSE, open = rlang::is_interactive() )
ggsave2( plot = ggplot2::last_plot(), dir = NULL, name = "Plot", xt = "png", dpi = 600, width = 21, height, scale = 1, replace = FALSE, open = rlang::is_interactive() )
plot |
The plot, created with ggplot2. |
dir |
If saved as file, the directory in which to save the html widget.
Default to temporary directory. Set global option |
name |
The name of the file to save. |
xt |
The extension name, when saving as image (interactive graph will always be .html). |
dpi |
The resolution. |
width |
The width in centimeters. |
height |
The height in centimeters. By default, |
scale |
Fixed ratio between horizontal and vertical axes. |
replace |
Replace file ? By default, number added to find a new name. |
open |
Should the resulting file be opened at once ? |
Creates a file, and opens it in 'RStudio' viewer, as a side effect.
Multiple Tables for Hierarchical Clusters
HCPC_tab( data, row_vars = character(), clust, wt, excl = character(), color = "diff", pct = "col", row_tot = "% of population", ... )
HCPC_tab( data, row_vars = character(), clust, wt, excl = character(), color = "diff", pct = "col", row_tot = "% of population", ... )
data |
A data frame. |
row_vars |
<tidy-select> The row variables of the table, to cross with the clusters. Typically, actives variables of the MCA. |
clust |
In columns, the variable with the clusters, typically made with hierarchical
clustering functions like |
wt |
The name of the weight variable. Leave empty for unweighted results. |
excl |
The name of the levels to exclude, as a character vector. |
color |
The type of colors to print, see |
pct |
The type of percentages to print, see |
row_tot |
The name of the total line (frequencies of each cluster) |
... |
Additional arguments to pass to |
A tibble
of class tab
, possibly with colored reading helpers.
data(tea, package = "FactoMineR") res.mca_3axes <- MCA2(tea, active_vars = 1:18, ncp = 3) cah <- FactoMineR::HCPC(res.mca_3axes, nb.clust = 6, graph = FALSE) tea$clust <- cah$data.clust$clust HCPC_tab(tea, row_vars = all_of(names(tea)[1:18]), clust = "clust") #|> #tabxplor::tab_kable()
data(tea, package = "FactoMineR") res.mca_3axes <- MCA2(tea, active_vars = 1:18, ncp = 3) cah <- FactoMineR::HCPC(res.mca_3axes, nb.clust = 6, graph = FALSE) tea$clust <- cah$data.clust$clust HCPC_tab(tea, row_vars = all_of(names(tea)[1:18]), clust = "clust") #|> #tabxplor::tab_kable()
Title Scale color dark for MCA.
material_colors_dark()
material_colors_dark()
A character vector of color codes, with color names.
material_colors_dark()
material_colors_dark()
Title Scale color light for MCA.
material_colors_light()
material_colors_light()
A character vector of color codes, with color names.
material_colors_light()
material_colors_light()
A table to help to interpret the meaning of axes in multiple correspondence analysis (MCA), based on Brigitte Le Roux, Analyse geometrique des donnees multidimensionnelles, Dunod, Paris, 2014 / Brigitte Le Roux and Henri Rouanet, Geometric data analysis : from correspondence analysis to structured data analysis, Kluwer, Boston, 2004. Only levels whose relative contribution to the variance of axis is superior to the mean contribution are kept. The spread between positive levels and negative levels of the same variable is calculated in percentages of the variance of the question/variable.
mca_interpret( res.mca = res.mca, axes = 1:min(res.mca$call$ncp, 5), type = c("html", "console") )
mca_interpret( res.mca = res.mca, axes = 1:min(res.mca$call$ncp, 5), type = c("html", "console") )
res.mca |
An object created with |
axes |
The axes to interpret, as an integer vector. Default to the first five axes. |
type |
By default, a html table is printed. Set to |
An html table (or a tibble
).
data(tea, package = "FactoMineR") res.mca <- MCA2(tea, active_vars = 1:18) mca_interpret(res.mca)
data(tea, package = "FactoMineR") res.mca <- MCA2(tea, active_vars = 1:18) mca_interpret(res.mca)
A user-friendly wrapper around MCA
, made to
work better with ggfacto functions like ggmca
. All variables can
be selected by many different expressions, in the way of the 'tidyverse'.
No supplementary vars are to be provided here, since they can be added afterward
in ggmca
.
MCA2(data, active_vars, wt, excl, ncp = 5, graph = FALSE, ...)
MCA2(data, active_vars, wt, excl, ncp = 5, graph = FALSE, ...)
data |
The data frame. |
active_vars |
|
wt |
|
excl |
A character vector of regular expressions to exclude "junk" categories. Any level of an active variable with any of the detected patterns is not taken into account in the calculation of axes (which is called specific multiple correspondence analysis). |
ncp |
The number of axes to keep. Default to 5. |
graph |
By default no graph is made, since the result can be ploted with
|
... |
Additionnal arguments to pass to |
A 'res.mca' object, with all the data necessary to draw the MCA.
data(tea, package = "FactoMineR") res.mca <- MCA2(tea, active_vars = 1:18) res.mca %>% ggmca(tea, sup_vars = c("SPC"), ylim = c(NA, 1.2), text_repel = TRUE) %>% ggi() #to make the graph interactive
data(tea, package = "FactoMineR") res.mca <- MCA2(tea, active_vars = 1:18) res.mca %>% ggmca(tea, sup_vars = c("SPC"), ylim = c(NA, 1.2), text_repel = TRUE) %>% ggi() #to make the graph interactive
Simple Mean and SD Summary
mean_sd_tab(data, vars, wt)
mean_sd_tab(data, vars, wt)
data |
A data.frame. |
vars |
<tidy-select> The names of the numeric variables to compute means and sds with. |
wt |
The name of the weight variable, if needed. |
A data.frame.
mean_sd_tab(mtcars, 1:7)
mean_sd_tab(mtcars, 1:7)
Colored Table to Help Interpretation of Principal Component Analysis
pca_interpret(res.pca, axes = 1:3)
pca_interpret(res.pca, axes = 1:3)
res.pca |
The result of |
axes |
The axes to print, as a numeric vector. |
A tibble of class tabxplor
data(mtcars, package = "datasets") mtcars <- mtcars[1:7] |> dplyr::rename(weight = wt) res.pca <- FactoMineR::PCA(mtcars, graph = FALSE) pca_interpret(res.pca)
data(mtcars, package = "datasets") mtcars <- mtcars[1:7] |> dplyr::rename(weight = wt) res.pca <- FactoMineR::PCA(mtcars, graph = FALSE) pca_interpret(res.pca)
A user-friendly wrapper around PCA
, made to
work better with ggfacto functions like ggpca_cor_circle
.
All variables can be selected by many different expressions, in the way of
the 'tidyverse'. No supplementary vars are to be provided here,
since they can be added afterward.
PCA2( data, active_vars, wt, col.w = NULL, ind_name, scale.unit = TRUE, ind.sup = NULL, ncp = 5, graph = FALSE, ... )
PCA2( data, active_vars, wt, col.w = NULL, ind_name, scale.unit = TRUE, ind.sup = NULL, ncp = 5, graph = FALSE, ... )
data |
The data frame. |
active_vars |
<tidy-select> The names of the active variables. |
wt |
The name of the row weight variable |
col.w |
The weights of the columns, as a numeric vector of the same length than 'active_vars.' |
ind_name |
Possibly, a variable with the names of the individuals. |
scale.unit |
A boolean, if 'TRUE' (value set by default) then data are scaled to unit variance. |
ind.sup |
A vector indicating the indexes of the supplementary individuals. |
ncp |
Number of dimensions kept in the results (by default 5). |
graph |
A boolean, set to 'TRUE' to display the base graph. |
... |
Additional arguments to pass to |
A 'res.pca' object, with all the data necessary to draw the PCA.
active_vars <- c("mpg", "cyl", "hp", "drat", "qsec") res.pca <- PCA2(mtcars, tidyselect::all_of(active_vars) )
active_vars <- c("mpg", "cyl", "hp", "drat", "qsec") res.pca <- PCA2(mtcars, tidyselect::all_of(active_vars) )
Modified odd ratios plot from 'finalfit'
pers_or_plot( .data, dependent, explanatory, random_effect = NULL, factorlist = NULL, glmfit = NULL, confint_type = NULL, remove_ref = FALSE, break_scale = NULL, column_space = c(-0.5, 0, 0.2), dependent_label = NULL, prefix = "", suffix = ": OR (95% CI, p-value)", table_text_size = 5, title_text_size = 18, plot_opts = NULL, table_opts = NULL, return_df = FALSE, ... )
pers_or_plot( .data, dependent, explanatory, random_effect = NULL, factorlist = NULL, glmfit = NULL, confint_type = NULL, remove_ref = FALSE, break_scale = NULL, column_space = c(-0.5, 0, 0.2), dependent_label = NULL, prefix = "", suffix = ": OR (95% CI, p-value)", table_text_size = 5, title_text_size = 18, plot_opts = NULL, table_opts = NULL, return_df = FALSE, ... )
.data |
Data frame. |
dependent |
Character vector of length 1: name of dependent variable (must have 2 levels). |
explanatory |
Character vector of any length: name(s) of explanatory variables. |
random_effect |
Character vector of length 1, name of random effect variable. |
factorlist |
Option to provide output directly from |
glmfit |
Option to provide output directly from |
confint_type |
One of |
remove_ref |
Logical. Remove reference level for factors. |
break_scale |
Manually specify x-axis breaks in format |
column_space |
Adjust table column spacing. |
dependent_label |
Main label for plot. |
prefix |
Plots are titled by default with the dependent variable. This adds text before that label. |
suffix |
Plots are titled with the dependent variable. This adds text after that label. |
table_text_size |
Alter font size of table text. |
title_text_size |
Alter font size of title text. |
plot_opts |
A list of arguments to be appended to the ggplot call by |
table_opts |
A list of arguments to be appended to the ggplot table call by
|
return_df |
To return the dataframe. |
... |
Other parameters. |
The odd ratios plot as a ggplot2
object.
A ggplot2 Theme for Geometrical Data Analysis
theme_facto( res, axes = c(1, 2), legend.position = c("none", "left", "right", "bottom", "top"), no_color_scale = FALSE, size_scale_max = 8, xlim, ylim )
theme_facto( res, axes = c(1, 2), legend.position = c("none", "left", "right", "bottom", "top"), no_color_scale = FALSE, size_scale_max = 8, xlim, ylim )
res |
|
axes |
The axes to print, as a numeric vector of length 2. |
legend.position |
One of |
no_color_scale |
When TRUE, you can provide color_scale next without warning. |
size_scale_max |
Maximum size of the points. |
xlim |
Horizontal axe limits. |
ylim |
Vertical axe limits. |
A list of ggplot2 objects.