Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 4bf08c6
Showing
8 changed files
with
192 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
^.*\.Rproj$ | ||
^\.Rproj\.user$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.Rproj.user | ||
.Rhistory | ||
.RData |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
Package: factoextra | ||
Type: Package | ||
Title: Visualization of FactoMineR outputs (PCA, CA, MCA) using ggplot2 | ||
Version: 1.0.0 | ||
Date: 2015-02-21 | ||
Author: Alboukadel Kassambara <alboukadel.kassambara@gmail.com> | ||
Maintainer: Alboukadel kassambara <alboukadel.kassambara@gmail.com> | ||
Description: Provide easy to use functions to visualize FactoMineR PCA, CA and MCA outputs using ggplot2 | ||
License: GPL-3 | ||
Depends: FactoMineR, ggplot2 | ||
Imports: FactoMineR, ggplot2 | ||
VignetteBuilder: knitr | ||
URL: htt://www.sthda.com | ||
BugReports:https://github.com/kassambara/factoextra/issues |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
exportPattern("^[[:alpha:]]+") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#' Screeplot : Plots the variances/eigenvalues against the number of dimensions | ||
#' | ||
#' @param X Object of class PCA, MCA, CA (from FactoMineR) | ||
#' @param choice Character specifing the type of the data to be plotted. | ||
#' Allowed values are "variance" or "eigenvalue" | ||
#' @param geom Character specifing the geometry to be used for the graph. | ||
#' Allowed values are "bar" for barplot, "line" for lineplot or c("bar", "line") to use both type | ||
#' @param barfill Fill color for bar plot | ||
#' @param barcolor Outline color for bar plot | ||
#' @param linecolor Color for line plot (when geom contains "line") | ||
#' @param ncp Numeric value specifing the number of components to be shown | ||
#' @param addlabels Logical value. If TRUE, labels are added at the top of bars or points | ||
#' showing the information retained by each dimension | ||
#' | ||
#' @return a ggplot2 plot | ||
#' @author Alboukadel Kassambara \email{alboukadel.kassambara@@gmail.com} | ||
#' @references http://www.sthda.com | ||
#' @examples | ||
#' \donttest{ | ||
#' library("FactoMineR") | ||
#' data(decathlon) | ||
#' res.pca <- PCA(decathlon, quanti.sup = 11:12, quali.sup=13) | ||
#' fviz_screeplot(res.pca) | ||
#' } | ||
fviz_screeplot<-function(X, choice=c("variance", "eigenvalue"), geom=c("bar", "line"), | ||
barfill="steelblue", barcolor="steelblue", linecolor = "black", | ||
ncp=5, addlabels=FALSE, ...) | ||
{ | ||
library("ggplot2") | ||
|
||
eig <- X$eig | ||
if(ncp > 0 & nrow(eig) > ncp) eig <- eig[1:ncp, , drop=FALSE] | ||
|
||
title <- "Scree plot" | ||
xlab <- "Dimensions" | ||
ylab <- "Percentage of variances" | ||
if(inherits(X, "PCA")) xlab = "Principal Components" | ||
|
||
choice <- choice[1] | ||
if(choice=="eigenvalue") { | ||
eig <- eig[,1] | ||
text_labels <- round(eig,1) | ||
ylab <- "Eigenvalue" | ||
} | ||
else if(choice=="variance") { | ||
eig <- eig[,2] | ||
text_labels <- paste0(round(eig,1), "%") | ||
} | ||
else stop("Allowed values for the argument choice are : 'variance' or 'eigenvalue'") | ||
|
||
if(length(intersect(geom, c("bar", "line"))) == 0) | ||
stop("The specified value(s) for the argument geom are not allowed ") | ||
|
||
df.eig <- data.frame(dim = factor(1:length(eig)), eig=eig ) | ||
p <- ggplot(df.eig, aes(dim, eig, group=1 )) | ||
if("bar" %in% geom) p <- p + geom_bar(stat="identity", fill=barfill, color = barcolor,...) | ||
if("line" %in% geom) p <- p + geom_line(color = linecolor, ...)+ | ||
geom_point(shape=19, color=linecolor) | ||
if(addlabels) p <- p + geom_text(label = text_labels, | ||
vjust=-0.4, ...) | ||
p <- p + labs(title = title, x = xlab, y = ylab) | ||
|
||
p | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
Version: 1.0 | ||
|
||
RestoreWorkspace: Default | ||
SaveWorkspace: Default | ||
AlwaysSaveHistory: Default | ||
|
||
EnableCodeIndexing: Yes | ||
UseSpacesForTab: Yes | ||
NumSpacesForTab: 2 | ||
Encoding: UTF-8 | ||
|
||
RnwWeave: Sweave | ||
LaTeX: pdfLaTeX | ||
|
||
BuildType: Package | ||
PackageUseDevtools: Yes | ||
PackageInstallArgs: --no-multiarch --with-keep.source |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
\name{factoextra-package} | ||
\alias{factoextra-package} | ||
\alias{factoextra} | ||
\docType{package} | ||
\title{ | ||
Visualization of FactoMineR outputs (PCA, CA, MCA) using ggplot2 | ||
} | ||
\description{ | ||
Provide easy to use functions to visualize FactoMineR PCA, CA and MCA outputs using ggplot2 | ||
} | ||
\details{ | ||
\tabular{ll}{ | ||
Package: \tab factoextra\cr | ||
Type: \tab Package\cr | ||
Version: \tab 1.0.0\cr | ||
Date: \tab 2015-02-21\cr | ||
License: \tab GPL-3\cr | ||
} | ||
~~ An overview of how to use the package, including the most important functions ~~ | ||
} | ||
\author{ | ||
Alboukadel Kassambara | ||
|
||
Maintainer: Alboukadel Kassambara <alboukadel.kassambara@gmail.com> | ||
} | ||
\references{ | ||
http://www.sthda.com | ||
} | ||
~~ Optionally other standard keywords, one per line, from file KEYWORDS in the R documentation directory ~~ | ||
\keyword{ package } | ||
\seealso{ | ||
} | ||
\examples{ | ||
library("FactoMineR") | ||
data(decathlon) | ||
res.pca <- PCA(decathlon, quanti.sup = 11:12, quali.sup=13) | ||
|
||
# Screeplot | ||
fviz_screeplot(res.pca) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
% Generated by roxygen2 (4.1.0): do not edit by hand | ||
% Please edit documentation in R/fviz_screeplot.R | ||
\name{fviz_screeplot} | ||
\alias{fviz_screeplot} | ||
\title{Screeplot : Plots the variances against the number of dimensions} | ||
\usage{ | ||
fviz_screeplot(X, choice = c("variance", "eigenvalue"), geom = c("bar", | ||
"line"), barfill = "steelblue", barcolor = "steelblue", | ||
linecolor = "black", ncp = 5, addlabels = FALSE, ...) | ||
} | ||
\arguments{ | ||
\item{X}{Object of class PCA, MCA, CA (from FactoMineR)} | ||
|
||
\item{choice}{Character specifing the type of the data to be plotted. | ||
Allowed values are "variance" or "eigenvalue"} | ||
|
||
\item{geom}{Character specifing the geometry to be used for the graph. | ||
Allowed values are "bar" for barplot, "line" for lineplot or c("bar", "line") to use both type} | ||
|
||
\item{barfill}{Fill color for bar plot} | ||
|
||
\item{barcolor}{Outline color for bar plot} | ||
|
||
\item{linecolor}{Color for line plot (when geom contains "line")} | ||
|
||
\item{ncp}{Numeric value specifing the number of components to be shown} | ||
|
||
\item{addlabels}{Logical value. If TRUE, labels are added at the top of bars or points | ||
showing the information retained by each dimension} | ||
} | ||
\value{ | ||
a ggplot2 plot | ||
} | ||
\description{ | ||
Screeplot : Plots the variances against the number of dimensions | ||
} | ||
\examples{ | ||
\donttest{ | ||
library("FactoMineR") | ||
data(decathlon) | ||
res.pca <- PCA(decathlon, quanti.sup = 11:12, quali.sup=13) | ||
fviz_screeplot(res.pca) | ||
} | ||
} | ||
\author{ | ||
Alboukadel Kassambara \email{alboukadel.kassambara@gmail.com} | ||
} | ||
\references{ | ||
http://en.sthda.com | ||
} | ||
|