Skip to content

Commit

Permalink
point shapes can be specified like colour palettes
Browse files Browse the repository at this point in the history
  • Loading branch information
dicook committed Mar 7, 2024
1 parent faa90ce commit 1216e88
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 7 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 4 additions & 2 deletions R/display-groupxy.r
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
}
Expand Down
6 changes: 4 additions & 2 deletions R/display-xy.r
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
}
Expand Down
5 changes: 3 additions & 2 deletions R/util.r
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
}
4 changes: 4 additions & 0 deletions man/display_groupxy.Rd

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

4 changes: 4 additions & 0 deletions man/display_xy.Rd

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

2 changes: 1 addition & 1 deletion man/mapShapes.Rd

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

0 comments on commit 1216e88

Please sign in to comment.