Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
kassambara committed Feb 21, 2015
0 parents commit 4bf08c6
Show file tree
Hide file tree
Showing 8 changed files with 192 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .Rbuildignore
@@ -0,0 +1,2 @@
^.*\.Rproj$
^\.Rproj\.user$
3 changes: 3 additions & 0 deletions .gitignore
@@ -0,0 +1,3 @@
.Rproj.user
.Rhistory
.RData
14 changes: 14 additions & 0 deletions DESCRIPTION
@@ -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
1 change: 1 addition & 0 deletions NAMESPACE
@@ -0,0 +1 @@
exportPattern("^[[:alpha:]]+")
64 changes: 64 additions & 0 deletions R/fviz_screeplot.R
@@ -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
}
17 changes: 17 additions & 0 deletions factoextra.Rproj
@@ -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
40 changes: 40 additions & 0 deletions man/factoextra-package.Rd
@@ -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)
}
51 changes: 51 additions & 0 deletions man/fviz_screeplot.Rd
@@ -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
}

0 comments on commit 4bf08c6

Please sign in to comment.