Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement variable label renaming. You can now rename the labels of … #35

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ Description: A ggplot2 based biplot. It provides a drop-in
replacement for biplot.princomp(). It implements a
biplot and scree plot using ggplot2.
Depends:
ggplot2, plyr, scales, grid
ggplot2,
plyr,
scales,
grid
License: GPL-2
URL: http://github.com/vqv/ggbiplot
Collate:
'ggbiplot.r'
'ggscreeplot.r'
RoxygenNote: 5.0.1
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# Generated by roxygen2: do not edit by hand

export(ggbiplot)
export(ggscreeplot)
10 changes: 8 additions & 2 deletions R/ggbiplot.r
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
#' @param varname.size size of the text for variable names
#' @param varname.adjust adjustment factor the placement of the variable names, >= 1 means farther from the arrow
#' @param varname.abbrev whether or not to abbreviate the variable names
#' @param varname.labels vector of labels to use instead of prcomp rownames
#' @param varname.labels.expr should varname.labels be interpreted as expressions to be parsed?
#'
#' @return a ggplot2 plot
#' @export
Expand All @@ -52,7 +54,7 @@ ggbiplot <- function(pcobj, choices = 1:2, scale = 1, pc.biplot = TRUE,
var.axes = TRUE,
circle = FALSE, circle.prob = 0.69,
varname.size = 3, varname.adjust = 1.5,
varname.abbrev = FALSE, ...)
varname.abbrev = FALSE, varname.labels = NULL, varname.labels.expr = F, ...)
{
library(ggplot2)
library(plyr)
Expand Down Expand Up @@ -138,6 +140,10 @@ ggbiplot <- function(pcobj, choices = 1:2, scale = 1, pc.biplot = TRUE,
} else {
df.v$varname <- rownames(v)
}

if(!missing(varname.labels)) {
df.v$varname = varname.labels
}

# Variables for text label placement
df.v$angle <- with(df.v, (180/pi) * atan(yvar / xvar))
Expand Down Expand Up @@ -206,7 +212,7 @@ ggbiplot <- function(pcobj, choices = 1:2, scale = 1, pc.biplot = TRUE,
geom_text(data = df.v,
aes(label = varname, x = xvar, y = yvar,
angle = angle, hjust = hjust),
color = 'darkred', size = varname.size)
color = 'darkred', size = varname.size, parse = varname.labels.expr)
}
# Change the name of the legend for groups
# if(!is.null(groups)) {
Expand Down
1 change: 1 addition & 0 deletions ggbiplot.Rproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ LaTeX: XeLaTeX
BuildType: Package
PackageUseDevtools: Yes
PackageInstallArgs: --no-multiarch --with-keep.source
PackageRoxygenize: rd,collate,namespace
79 changes: 35 additions & 44 deletions man/ggbiplot.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 10 additions & 12 deletions man/ggscreeplot.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.