Skip to content

Commit 473e462

Browse files
authored
Merge pull request #42 from r-spatial/fix_box
Fix box
2 parents 830abc9 + 28e92f0 commit 473e462

File tree

6 files changed

+34
-8
lines changed

6 files changed

+34
-8
lines changed

DESCRIPTION

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: classInt
2-
Version: 0.4-8
3-
Date: 2022-09-22
2+
Version: 0.4-9
3+
Date: 2023-02-21
44
Title: Choose Univariate Class Intervals
55
Authors@R: c(
66
person("Roger", "Bivand", role=c("aut", "cre"), email="[email protected]", comment=c(ORCID="0000-0003-2392-6140")),
@@ -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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## Version 0.4-9
2+
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.
4+
15
## Version 0.4-8
26

37
- #18 and #38: `classIntervals()` has a new style `"box"`, where a box map is an augmented quartile map, with an additional lower and upper category. When there are lower outliers, then the starting point for the breaks is the minimum value, and the second break is the lower fence. When there are no lower outliers, then the starting point for the breaks will be the lower fence, and the second break is the minimum value (there will be no observations that fall in the interval between the lower fence and the minimum value) (@angela-li, @dieghernan).

R/classInt.R

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,9 @@ classIntervals <- function(var, n, style="quantile", rtimes=3, ..., intervalClos
357357

358358
dots <- list(...)
359359
iqr_mult <- ifelse(is.null(dots$iqr_mult), 1.5, dots$iqr_mult)
360+
stopifnot(iqr_mult >= 0)
360361
qtype <- ifelse(is.null(dots$type), 7, dots$type)
362+
legacy <- ifelse(is.null(dots$legacy), FALSE, dots$legacy)
361363

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

370372
# logic for lower and upper fences
371373
if (lofence < qv[1]) { # no lower outliers
372-
bb[1] <- lofence
373-
bb[2] <- floor(qv[1])
374+
if (legacy) {
375+
bb[1] <- lofence
376+
bb[2] <- floor(qv[1])
377+
} else {
378+
bb[1] <- -Inf
379+
bb[2] <- lofence
380+
}
374381
} else {
375382
bb[2] <- lofence
376383
bb[1] <- qv[1]
377384
}
378385
if (upfence > qv[5]) { # no upper outliers
379-
bb[7] <- upfence
380-
bb[6] <- ceiling(qv[5])
386+
if (legacy) {
387+
bb[7] <- upfence
388+
bb[6] <- ceiling(qv[5])
389+
} else {
390+
bb[7] <- +Inf
391+
bb[6] <- upfence
392+
}
381393
} else {
382394
bb[6] <- upfence
383395
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+
expect_error(classIntervals(x, style="box", iqr_mult=-1))

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}; the value must not be negative. 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)