diff --git a/DESCRIPTION b/DESCRIPTION index 2967ebf..2f64bd8 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: ggbiplot Type: Package Title: A Grammar of Graphics Implementation of Biplots -Version: 0.6.2 -Date: 2024-01-06 +Version: 0.6.3 +Date: 2024-04-24 Authors@R: c( person(c("Vincent", "Q."), "Vu", , "vqv@stat.osu.edu", role = c("aut"), comment = c(ORCID = "0000-0002-4689-0497")), diff --git a/NEWS.md b/NEWS.md index 5cf0ec1..afce2d9 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +## Version 0.6.3 + +- Fix axis label spacing + ## Version 0.6.2 This is a modest upgrade to the initial release, adding a number of features. diff --git a/R/ggbiplot.r b/R/ggbiplot.r index a97bfcb..3afe7d4 100644 --- a/R/ggbiplot.r +++ b/R/ggbiplot.r @@ -274,7 +274,7 @@ ggbiplot <- function(pcobj, # Change the title labels for the axes if(obs.scale == 0) { - u.axis.labs <- paste('standardized', axis.title, choices, sep='') + u.axis.labs <- paste('standardized ', axis.title, choices, sep='') } else { u.axis.labs <- paste(axis.title, choices, sep='') } diff --git a/discussion/biplot-packages.xlsx b/discussion/biplot-packages.xlsx index d2e4721..ff04d14 100644 Binary files a/discussion/biplot-packages.xlsx and b/discussion/biplot-packages.xlsx differ diff --git a/examples/ggvector.R b/examples/ggvector.R new file mode 100644 index 0000000..fddbedb --- /dev/null +++ b/examples/ggvector.R @@ -0,0 +1,46 @@ +#' Draw labeled vectors in a ggplot scene +#' +#' @param x,y coordinates of vector ends +#' @param label text labels for vector ends +#' @param scale scale factor for vectors +#' @param origin origin of vectors +#' @param arrow_style style for the vector arrows +#' @param color colors for vectors +#' @param linewidth linewidth for vectors +#' @param adjust adjustment offset for labels +#' @param size text size for labels +#' +#' @return +#' @export +#' +#' @examples +ggvector <- function(x, y, label, + scale = 1, + origin = c(0, 0), + arrow_style, + color, + linewidth = 1.4, + adjust = 1.25, + size = 3 + ){ + + if(missing(arrow_style)) arrow_style <- arrow(length = unit(1/2, 'picas'), + type="closed", + angle=15) + # Variables for text label placement + df <- data.frame(x = x, y = y, label = label) + df$angle <- with(df, (180/pi) * atan(y / x)) + df$hjust <- with(df, (1 - adjust * sign(x)) / 2) + + geom_segment(data = df, + aes(x = origin[1], y = origin[2], + xend = x, yend = y), + arrow = arrow_style, + color = color, + linewidth = linewidth) + + geom_text(data = df, + aes(label = label, x = x, y = y, + angle = angle, hjust = hjust), + color = color, size = size) + +} \ No newline at end of file