From 1216e88a8d1cd34ced7309fa8775125a16e56adf Mon Sep 17 00:00:00 2001 From: dicook Date: Fri, 8 Mar 2024 09:11:14 +1100 Subject: [PATCH] point shapes can be specified like colour palettes --- NEWS.md | 1 + R/display-groupxy.r | 6 ++++-- R/display-xy.r | 6 ++++-- R/util.r | 5 +++-- man/display_groupxy.Rd | 4 ++++ man/display_xy.Rd | 4 ++++ man/mapShapes.Rd | 2 +- 7 files changed, 21 insertions(+), 7 deletions(-) diff --git a/NEWS.md b/NEWS.md index 4fcb4801..fec97da3 100644 --- a/NEWS.md +++ b/NEWS.md @@ -7,6 +7,7 @@ * palette can now be a vector of values * a new projection pursuit index for finding anomalies relative to a null variance-covariance matrix. +* point shapes can now be specified like palettes # tourr 1.1.0 diff --git a/R/display-groupxy.r b/R/display-groupxy.r index 3d8d283c..c72cbaaf 100644 --- a/R/display-groupxy.r +++ b/R/display-groupxy.r @@ -20,6 +20,8 @@ #' @param edges.col colour of edges to be plotted, Defaults to "black" #' @param edges.width line width for edges, default 1 #' @param palette name of color palette for point colour, used by \code{\link{hcl.colors}}, default "Zissou 1" +#' @param shapeset numbers corresponding to shapes in base R points, to use for mapping +#' categorical variable to shapes, default=c(15:17, 23:25) #' @param ... other arguments passed on to \code{\link{animate}} and #' \code{\link{display_groupxy}} #' @export @@ -39,7 +41,7 @@ display_groupxy <- function(centr = TRUE, axes = "center", half_range = NULL, col = "black", pch = 20, cex = 1, edges = NULL, edges.col = "black", edges.width=1, group_by = NULL, plot_xgp = TRUE, - palette = "Zissou 1", ...) { + palette = "Zissou 1", shapeset=c(15:17, 23:25), ...) { labels <- NULL # If colors are a variable, convert to colors @@ -53,7 +55,7 @@ display_groupxy <- function(centr = TRUE, axes = "center", half_range = NULL, } # If shapes are a variable, convert shapes if (is.factor(pch)) { - shapes <- mapShapes(pch) + shapes <- mapShapes(pch, shapeset) } else { shapes <- pch } diff --git a/R/display-xy.r b/R/display-xy.r index 837eba8d..0c484e48 100644 --- a/R/display-xy.r +++ b/R/display-xy.r @@ -20,6 +20,8 @@ #' @param ellsize This can be considered the equivalent of a critical value, used to #' scale the ellipse larger or smaller to capture more or fewer anomalies. Default 3. #' @param palette name of color palette for point colour, used by \code{\link{hcl.colors}}, default "Zissou 1" +#' @param shapeset numbers corresponding to shapes in base R points, to use for mapping +#' categorical variable to shapes, default=c(15:17, 23:25) #' @param ... other arguments passed on to \code{\link{animate}} and #' \code{\link{display_xy}} #' @importFrom graphics legend @@ -67,7 +69,7 @@ display_xy <- function(center = TRUE, axes = "center", half_range = NULL, edges = NULL, edges.col = "black", edges.width=1, obs_labels = NULL, ellipse = NULL, ellsize = 3, - palette="Zissou 1", ...) { + palette="Zissou 1", shapeset=c(15:17, 23:25), ...) { # Needed for CRAN checks labels <- NULL gps <- NULL @@ -84,7 +86,7 @@ display_xy <- function(center = TRUE, axes = "center", half_range = NULL, } # If shapes are a variable, convert shapes if (is.factor(pch)) { - shapes <- mapShapes(pch) + shapes <- mapShapes(pch, shapeset) } else { shapes <- pch } diff --git a/R/util.r b/R/util.r index dce0ea12..002bd315 100644 --- a/R/util.r +++ b/R/util.r @@ -137,8 +137,9 @@ mapColors <- function(x, palette) { #' #' @param x vector #' @export -mapShapes <- function(x) { +mapShapes <- function(x, shapeset) { n <- length(unique(x)) - shapes <- c(15:17, 23:25) + stopifnot(length(shapeset) >= n) + shapes <- shapeset shapes[as.numeric(x)] } diff --git a/man/display_groupxy.Rd b/man/display_groupxy.Rd index bb873349..0db34e08 100644 --- a/man/display_groupxy.Rd +++ b/man/display_groupxy.Rd @@ -18,6 +18,7 @@ display_groupxy( group_by = NULL, plot_xgp = TRUE, palette = "Zissou 1", + shapeset = c(15:17, 23:25), ... ) @@ -51,6 +52,9 @@ If not set, defaults to maximum distance from origin to each row of data.} \item{palette}{name of color palette for point colour, used by \code{\link{hcl.colors}}, default "Zissou 1"} +\item{shapeset}{numbers corresponding to shapes in base R points, to use for mapping +categorical variable to shapes, default=c(15:17, 23:25)} + \item{...}{other arguments passed on to \code{\link{animate}} and \code{\link{display_groupxy}}} diff --git a/man/display_xy.Rd b/man/display_xy.Rd index 692ce629..7ad22e21 100644 --- a/man/display_xy.Rd +++ b/man/display_xy.Rd @@ -19,6 +19,7 @@ display_xy( ellipse = NULL, ellsize = 3, palette = "Zissou 1", + shapeset = c(15:17, 23:25), ... ) @@ -56,6 +57,9 @@ scale the ellipse larger or smaller to capture more or fewer anomalies. Default \item{palette}{name of color palette for point colour, used by \code{\link{hcl.colors}}, default "Zissou 1"} +\item{shapeset}{numbers corresponding to shapes in base R points, to use for mapping +categorical variable to shapes, default=c(15:17, 23:25)} + \item{...}{other arguments passed on to \code{\link{animate}} and \code{\link{display_xy}}} diff --git a/man/mapShapes.Rd b/man/mapShapes.Rd index d1df54a6..7b3ab960 100644 --- a/man/mapShapes.Rd +++ b/man/mapShapes.Rd @@ -4,7 +4,7 @@ \alias{mapShapes} \title{Map vector of factors to pch} \usage{ -mapShapes(x) +mapShapes(x, shapeset) } \arguments{ \item{x}{vector}