Skip to content

jasb3110/g.princals

Repository files navigation

$g.princals$

This script offers a method to enhance the visual appearance of plots generated by the PRINCALS function from the Gifi package in R (1), by building upon the source code of the original plotting function. Since PRINCALS produces complex outputs that require further processing for effective visualization, the script leverages the ggplot2 package (2) to improve both the aesthetics and clarity of the resulting plots.

Contents

Proposal

The $g.princals$ function is specifically designed to enhance the visual quality of plots generated by the plot.princals function from the Gifi package, which, by default, utilizes base R graphics (3). By leveraging the advanced capabilities of ggplot2 a package well known for its ability to produce high-quality, customizable graphics of $g.princals$ delivers a more refined and visually appealing output. This function includes options to generate a variety of plots, such as transformation plots, scree plots, loading plots, and biplots for hierarchical categorical variables (4).

Instruction

The $g.princals$ function overrides the default plot function in R to generate customized graphics for objects created by the princals function. Below are the available parameters and their default settings:

  • x: An object generated by princals(dataset).
  • plot.dim: A numeric vector specifying the dimensions to be plotted. Default is c(1, 2).
  • var.subset: Specifies a subset of variables to include. Default is "all".
  • max.plot.array: Maximum number of plots per array. Default is 2.
  • stepvec: A numeric vector indicating whether to include a step function in the plot (see princals documentation for details). Default is NA.
  • col.lines: Color of the lines in the plot. Default is "black".
  • main: Title of the plot. By default, it uses the name of the princals object.
  • show: Logical or numeric (TRUE/FALSE, T/F, 1/0) indicating whether to display the plots. Default is 1 (TRUE).
  • save: Logical or numeric (TRUE/FALSE, T/F, 1/0) indicating whether to save the plots. Default is 1 (TRUE).
  • name: A label or name for the princals object. Default is the name of the object.
  • units: Units for width and height. Default is "mm".
  • width]: Width of the output image. Default is 250mm.
  • height: Height of the output image. Default is 250mm.
  • res: Resolution of the image in pixels. Default is 300.
  • dispersion: Controls the spread of scores in the load plot. Default is 3, which corresponds to mean ± 3 * standard deviation.
  • point.size.loadplot: Size of the points in the load plot. Default is 1.
  • point.alpha.loadplot: Transparency level (alpha) of the points in the load plot. Default is 0.1.
  • language: Language for the plot labels. Options are "English" or "Spanish". Default is "English".
  • legend.position: Position of the legend. Options are "none", "left", "right", "bottom", and "top". Default is "right".
  • legend.group: Logical or numeric (TRUE/FALSE, T/F, 1/0) indicating whether to display grouped legends. Default is 1 (TRUE).

R code

Finally, figures generated by the $g.princals$ function was presented. If the label names are too long, it is recommended to shorten them using acronyms. A supporting script is also attached (5).

#to begin
setwd("~/file")
source(
"https://github.com/jasb3110/g.princals/blob/f286b26f79da57600c3e7f207a6f653f24028a76/g.princals.R"
)
library("Gifi")

# ordinal PCA of Gifi
fitord <- princals(ABC,ndim = 2)

#to use a g.princals

g.princals(fitord,
           save=0,
           show=1,
           dispersion =3,
           legend.group = 0)#show plots
                  
g.princals(fitord,
           save=0,
           show=1,
           dispersion =3,
           colour.group = c(rep("A",5),rep("B",6)),
           legend.group = 1,
           language = "spanish")#show plots

g.princals(fitord,
           save=1,
           show=1,
           dispersion =3,
           legend.group = 0)#save plots in PNG format

g.princals(fitord,
           save=1,
           show=0,
           dispersion =3,
           colour.group = c(rep("A",5),rep("B",6)),
           legend.group = 1,
           language = "spanish")#save plots in PNG format

Output

In this section, an R script and corresponding plots created using the $g.princals$ function are presented in Spanish, and group of variables.

Plot.1
Picture. Transplots of ABC dataset, just 1 to 4 variables
Plot.2
Picture. Transplots of ABC dataset, just 5 to 8 variables
Plot.3
Picture. Transplots of ABC dataset, just 9 to 11 variables
Plot.4
Picture. Screeplot of ABC dataset
Plot.5
Picture. Loadplot of ABC dataset
Plot.6
Picture. Biplot of ABC dataset

References

About

The best aesthetic plotting of princals function of Gifi package

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages