Skip to content

Commit d6b3453

Browse files
committed
addressing #41, avoiding breaks ceasing to be strictly ascending when no outliers etc.
1 parent 9fc8ba1 commit d6b3453

File tree

6 files changed

+28
-7
lines changed

6 files changed

+28
-7
lines changed

DESCRIPTION

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ Suggests:
1616
spData (>= 0.2.6.2),
1717
units,
1818
knitr,
19-
rmarkdown
19+
rmarkdown,
20+
tinytest
2021
NeedsCompilation: yes
2122
Description: Selected commonly used methods for choosing univariate class intervals for mapping or other graphics purposes.
2223
License: GPL (>= 2)

NEWS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## Version 0.4-9
22

3-
- #41 issues
3+
- #41 issues. The maximum and minimum breaks are set to \code{+Inf} and \code{-Inf} to avoid errors induced in the earlier version where breaks could cease to be strictly ascending. The \code{legacy=} argument with value \code{TRUE} may be used to revert to the previous behaviour.
44

55
## Version 0.4-8
66

R/classInt.R

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@ classIntervals <- function(var, n, style="quantile", rtimes=3, ..., intervalClos
358358
dots <- list(...)
359359
iqr_mult <- ifelse(is.null(dots$iqr_mult), 1.5, dots$iqr_mult)
360360
qtype <- ifelse(is.null(dots$type), 7, dots$type)
361+
legacy <- ifelse(is.null(dots$legacy), FALSE, dots$legacy)
361362

362363
qv <- unname(quantile(var, type=qtype))
363364
iqr <- iqr_mult * (qv[4] - qv[2])
@@ -369,15 +370,25 @@ classIntervals <- function(var, n, style="quantile", rtimes=3, ..., intervalClos
369370

370371
# logic for lower and upper fences
371372
if (lofence < qv[1]) { # no lower outliers
372-
bb[1] <- lofence
373-
bb[2] <- floor(qv[1])
373+
if (legacy) {
374+
bb[1] <- lofence
375+
bb[2] <- floor(qv[1])
376+
} else {
377+
bb[1] <- -Inf
378+
bb[2] <- lofence
379+
}
374380
} else {
375381
bb[2] <- lofence
376382
bb[1] <- qv[1]
377383
}
378384
if (upfence > qv[5]) { # no upper outliers
379-
bb[7] <- upfence
380-
bb[6] <- ceiling(qv[5])
385+
if (legacy) {
386+
bb[7] <- upfence
387+
bb[6] <- ceiling(qv[5])
388+
} else {
389+
bb[7] <- +Inf
390+
bb[6] <- upfence
391+
}
381392
} else {
382393
bb[6] <- upfence
383394
bb[7] <- qv[5]

inst/tinytest/test_box.R

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
library(classInt)
2+
set.seed(101)
3+
x <- rnorm(50)
4+
expect_error(print(classIntervals(x, style="box", iqr_mult=1.5, type=5, legacy=TRUE)))
5+
expect_inherits(classIntervals(x, style="box", iqr_mult=1.5, type=5), "classIntervals")
6+

man/classIntervals.Rd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ classIntervals2shingle(x)
7070
7171
The "maximum" style uses the Maximum Breaks method of classification finding the k - 1 largest differences in \code{var}. The mean of the values that generated the largest splits is used as the interval boundary.
7272
73-
The "box" style generates 7 breaks (therefore 6 categories) based on a box-and-whisker plot. First and last categories include the data values considered as outliers, and the four remaining categories are defined by the percentiles 25, 50 and 75 of the data distribution. By default, the identification of outliers is based on the interquantile range (IQR), so values lower than percentile 25 - 1.5 * IQR or higher than percentile 75 + 1.5 * IQR are considered as outliers. The multiplier applied to the IQR \code{iqr_mult = 1.5} may be modified through \code{\dots}. As in the \code{"quantile"} style, the \code{type=} argument may be used to choose the quantile algoritm (default 7).
73+
The "box" style generates 7 breaks (therefore 6 categories) based on a box-and-whisker plot. First and last categories include the data values considered as outliers, and the four remaining categories are defined by the percentiles 25, 50 and 75 of the data distribution. By default, the identification of outliers is based on the interquantile range (IQR), so values lower than percentile 25 - 1.5 * IQR or higher than percentile 75 + 1.5 * IQR are considered as outliers. The multiplier applied to the IQR \code{iqr_mult = 1.5} may be modified through \code{\dots}. As in the \code{"quantile"} style, the \code{type=} argument may be used to choose the quantile algoritm (default 7, standard boxplots use 5 or 2). From 0.4-9 and #41, the maximum and minimum are set to \code{+Inf} and \code{-Inf} to avoid errors induced in the earlier version where breaks could cease to be strictly ascending. The \code{legacy=} argument with value \code{TRUE} may be used to revert to the previous behaviour.
7474
7575
}
7676

tests/tinytest.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
if ( requireNamespace("tinytest", quietly=TRUE) ){
2+
tinytest::test_package("classInt")
3+
}

0 commit comments

Comments
 (0)