ggInterval extends ggplot2 for
interval-valued data. The package supports visualizations such as
scatter plots, histograms, index plots, radar plots, line plots, PCA
displays, and correlation heatmaps, while keeping the layered grammar
familiar to ggplot2 users.
This vignette focuses on source-portable examples that can be rebuilt
directly from the package. It uses built-in data, the bundled
data.csv file for the aggregation example, and optional
sections for packages such as HistDAWass and
MAINT.Data. The examples below use version 0.2.6; the four diagnostic
functions and stock.data.LH are not available in 0.2.5.
An interval-valued observation records an ordered pair of endpoints \([a_{ij}, b_{ij}]\) for unit \(i\) and variable \(j\). Its center is \(c_{ij}=(a_{ij}+b_{ij})/2\), its full range is \(r_{ij}=b_{ij}-a_{ij}\), and its half-width is \(h_{ij}=r_{ij}/2\). A center alone loses the range. The endpoints do not, by themselves, specify a distribution of values inside the interval. Assumptions used by particular summaries are stated below. The displays support descriptive exploration; they do not establish recognition accuracy, statistical significance, or estimator superiority.
data(facedata)
data(Environment)
facedata
#> # A tibble: 27 x 6
#> AD BC AH DH
#> * <symblc_n> <symblc_n> <symblc_n> <symblc_n>
#> 1 [155.00 : 157.00] [58.00 : 61.01] [100.45 : 103.28] [105.00 : 107.30]
#> 2 [154.00 : 160.01] [57.00 : 64.00] [101.98 : 105.55] [104.35 : 107.30]
#> 3 [154.01 : 161.00] [57.00 : 63.00] [99.36 : 105.65] [101.04 : 109.04]
#> 4 [168.86 : 172.84] [58.55 : 63.39] [102.83 : 106.53] [122.38 : 124.52]
#> 5 [169.85 : 175.03] [60.21 : 64.38] [102.94 : 108.71] [120.24 : 124.52]
#> 6 [168.76 : 175.15] [61.40 : 63.51] [104.35 : 107.45] [120.93 : 125.18]
#> 7 [155.26 : 160.45] [53.15 : 60.21] [95.88 : 98.49] [91.68 : 94.37]
#> 8 [156.26 : 161.31] [51.09 : 60.07] [95.77 : 99.36] [91.21 : 96.83]
#> 9 [154.47 : 160.31] [55.08 : 59.03] [93.54 : 98.98] [90.43 : 96.43]
#> 10 [164.00 : 168.00] [55.01 : 60.03] [120.28 : 123.04] [117.52 : 121.02]
#> # i 17 more rows
#> # i 2 more variables: EH <symblc_n>, GH <symblc_n>
Environment
#> # A tibble: 14 x 17
#> URBANICITY INCOMELEVEL
#> <symblc_m> <symblc_m>
#> 1 6:0.14 4:0.43 5:0.08 1:0.21... 25:0.91 75:0.02 50:0.07 90:...
#> 2 6:0.08 4:0.49 5:0.08 1:0.15... 25:0.56 75:0.15 50:0.29 90:...
#> 3 6:0.13 4:0.42 5:0.10 1:0.24... 25:0.16 75:0.32 50:0.18 90:...
#> 4 6:0.18 4:0.50 5:0.11 1:0.15... 25:0.12 75:0.18 50:0.07 90:...
#> 5 6:0.12 4:0.38 5:0.08 1:0.30... 25:0.11 75:0.27 50:0.27 90:...
#> 6 6:0.10 4:0.58 5:0.10 1:0.10... 25:0.04 75:0.12 50:0.06 90:...
#> 7 6:0.10 4:0.39 5:0.10 1:0.31... 25:0.14 75:0.20 50:0.61 90:...
#> 8 6:0.19 4:0.47 5:0.09 1:0.14... 25:0.99 75:0.01 50:0.00 90:...
#> 9 6:0.22 4:0.42 5:0.13 1:0.15... 25:0.73 75:0.04 50:0.21 90:...
#> 10 6:0.18 4:0.45 5:0.11 1:0.17... 25:0.22 75:0.41 50:0.30 90:...
#> 11 6:0.18 4:0.43 5:0.09 1:0.17... 25:0.12 75:0.30 50:0.28 90:...
#> 12 6:0.11 4:0.44 5:0.10 1:0.23... 25:0.11 75:0.39 50:0.37 90:...
#> 13 6:0.23 4:0.41 5:0.13 1:0.11... 25:0.05 75:0.30 50:0.10 90:...
#> 14 6:0.14 4:0.41 5:0.08 1:0.26... 25:0.21 75:0.07 50:0.69 90:...
#> # i 15 more variables: EDUCATION <symblc_m>, REGIONDEVELOPME <symblc_m>,
#> # CONTROL <symblc_n>, SATISFY <symblc_n>, INDIVIDUAL <symblc_n>,
#> # WELFARE <symblc_n>, HUMAN <symblc_n>, POLITICS <symblc_n>,
#> # BURDEN <symblc_n>, NOISE <symblc_n>, NATURE <symblc_n>, SEASETC <symblc_n>,
#> # MULTI <symblc_n>, WATERWASTE <symblc_n>, VEHICLE <symblc_n>
Subjects <- substr(rownames(facedata), 1, 3)
Subjects
#> [1] "FRA" "FRA" "FRA" "HUS" "HUS" "HUS" "INC" "INC" "INC" "ISA" "ISA" "ISA"
#> [13] "JPL" "JPL" "JPL" "KHA" "KHA" "KHA" "LOT" "LOT" "LOT" "PHI" "PHI" "PHI"
#> [25] "ROM" "ROM" "ROM"The face data contain 27 cases: nine subjects with three image sequences per subject and six interval-valued facial measurements in pixels. The stored values agree, up to printed rounding, with the table reported by Arce Garro and Rodriguez Rojas (2019). Each interval summarizes one image sequence; the rule that produced its endpoints is not stated in the inspected sources. Subject labels therefore identify the recorded cases, without implying a validated face-recognition procedure.
Environment contains 14 symbolic objects, with 13
interval variables and four modal variables (URBANICITY,
INCOMELEVEL, EDUCATION, and
REGIONDEVELOPME). The modal fields contain category codes
and proportions. The stored values were compared with the SODAS example
distributed with Umbleja, Ichino and Yaguchi (2020). The original
item-to-variable mapping, endpoint preprocessing, complete codebook, and
mapping of the urbanicity codes remain unresolved. Since 0.2.6 the INCOMELEVEL labels follow the source order
25, 75, 50, 90, 100; earlier versions listed them as 25, 50, 75, 90, 100
with the proportions in the same positions. The displays below describe
stored profiles and do not attach substantive meanings to the unresolved
codes.
ggInterval_scatterplot(
facedata,
aes(x = AD, y = BC, fill = Subjects),
showLabels = FALSE,
col = "black"
) +
scale_fill_brewer(palette = "Set1") +
labs(fill = "Subjects")Most plotting functions return ordinary ggplot objects.
The following exceptions matter when saving a result or adding
layers:
| Function | Returned object | Plot component |
|---|---|---|
ggInterval_hist() |
ggInterval_hist_result, with frequency
tables |
$plot |
ggInterval_2Dhist() |
List, with a cell table | $plot |
ggInterval_PCA() |
Augmented princomp object, with
$scores_interval |
$ggplotPCA |
ggInterval_radarplot(inOneFig = FALSE) |
Arranged grob list | Not an ordinary ggplot object |
The histogram result has a print method that draws its plot. Printing
a 2D-histogram list displays its nested plot and table; printing a PCA
result shows the PCA summary. ggInterval_PCA(plot = TRUE)
also draws its plot as a side effect. To add themes or other layers to
these three results, use the stored plot component, as illustrated
later. scale() applied to a symbolic table returns an
object whose $intervalData component contains the
standardized interval table.
The four diagnostic functions introduced below return ordinary
ggplot objects, with computed quantities available through
attr(plot, "interval_diagnostics"). They accept symbolic
interval tables, objects containing intervalData, or paired
numeric endpoint matrices supplied as
list(lower = ..., upper = ...). The variables
argument selects interval variables by name.
The CSV is installed with the package and located with system.file(), so
its use does not depend on the working directory. Its empty final column is
read as X and removed before excluding the identifier. The K-means output
below illustrates one unseeded run; independently repeated cluster memberships
and summaries can vary, and cluster labels and row order are not fixed.
Diagnosis-based aggregation uses the observed groups and is deterministic.
breastData <- read.csv(system.file("extdata", "data.csv",
package = "ggInterval", mustWork = TRUE))
breastData$X <- NULL
breastData <- dplyr::select(breastData, -id)
breastData_kmeans <- classic2sym(breastData, groupby = "kmeans", k = 5)
head(breastData_kmeans$intervalData[, 1:4])
#> # A tibble: 5 x 4
#> diagnosis radius_mean texture_mean perimeter_mean
#> <symblc_m> <symblc_n> <symblc_n> <symblc_n>
#> 1 B:0.04 M:0.96 [13.81 : 19.59] [11.89 : 39.28] [91.56 : 132.40]
#> 2 B:0.98 M:0.02 [6.98 : 13.05] [9.71 : 33.81] [43.79 : 85.09]
#> 3 B:0.68 M:0.32 [11.84 : 16.30] [10.89 : 30.72] [77.93 : 109.80]
#> 4 B:0.00 M:1.00 [20.73 : 28.11] [17.25 : 31.12] [135.70 : 188.50]
#> 5 B:0.00 M:1.00 [15.50 : 24.25] [10.38 : 32.47] [102.90 : 166.20]
breastData_diag <- classic2sym(breastData, groupby = "diagnosis")
head(breastData_diag$intervalData[, 1:4])
#> radius_mean texture_mean perimeter_mean area_mean
#> 1 [6.98 : 17.85] [9.71 : 33.81] [43.79 : 114.60] [143.50 : 992.10]
#> 2 [10.95 : 28.11] [10.38 : 39.28] [71.90 : 188.50] [361.60 : 2,501.00]The center-based mean is supplied by the symbolic methods in
RSDA. sd(facedata) uses the Billard mixture
standard deviation by default; it includes a uniform-within-interval
variance term \(h_{ij}^2/3\) and is not
the sample standard deviation of the centers. The explicit
method = "BD" below selects the Billard–Diday covariance
and its matching correlation normalization. B denotes
Billard, and centers gives ordinary sample statistics of
the interval centers. Correlations require positive denominator
variances.
BG is retained as the software label for Bertrand–Goupil
covariance and correlation. The covariance formula is documented in
Irpino and Verde (2015), Equation (24), where it is attributed to
Bertrand and Goupil. The original Bertrand–Goupil chapter gives
univariate means and variances but does not define a covariance or
correlation. The implemented BG covariance is
\[ C_{BG}(X,Y)=\frac{1}{n}\sum_{i=1}^n (c_{Xi}-\bar c_X)(c_{Yi}-\bar c_Y). \]
The centers covariance instead uses divisor \(n-1\). The package divides BG covariance by
\(\sqrt{C_{BG}(X,X)C_{BG}(Y,Y)}\),
giving Pearson correlation of the centers when their variances are
positive. This differs from Equation (30) of Irpino and Verde, which
uses mixture standard deviations in the denominator. The BG option does
not implement the Wasserstein-based statistics proposed in that article.
See ?cov and ?cor for formulas and
references.
mean(facedata)
#> # A tibble: 1 x 6
#> AD BC AH DH EH GH
#> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 163. 60.0 113. 113. 59.8 57.7
sd(facedata)
#> # A tibble: 1 x 6
#> AD BC AH DH EH GH
#> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 6.84 4.58 8.98 9.40 4.24 4.78
cov(facedata$AD, facedata$BC, method = "BD")
#> [1] 21.47015
cor(facedata$AD, facedata$BC, method = "BD")
#> [1] 0.6846339
summary(facedata$AD)
#> <symbolic_interval[7]>
#> Min. 1st Qu. Median Mean
#> [149.34 : 155.32] [154.56 : 158.91] [163.00 : 167.07] [162.90 : 162.90]
#> 3rd Qu. Max. Std.
#> [167.13 : 171.19] [169.85 : 175.15] [6.84 : 6.84]
summary(Environment[1:3, ])
#> $symbolic_interval
#> CONTROL SATISFY INDIVIDUAL
#> Min. [-723.25 : -339.65] [-134.15 : 191.17] [-658.77 : -299.04]
#> 1st Qu. [-483.56 : -124.77] [-134.03 : 221.00] [-625.52 : -268.47]
#> Median [-243.86 : 90.10] [-133.91 : 250.83] [-592.28 : -237.90]
#> Mean [-201.35 : -201.35] [68.96 : 68.96] [-398.20 : -398.20]
#> 3rd Qu. [-219.66 : 147.05] [-104.46 : 282.82] [-542.15 : -173.54]
#> Max. [-195.44 : 203.99] [-75.00 : 314.80] [-492.03 : -109.17]
#> Std. [258.04 : 258.04] [109.12 : 109.12] [127.06 : 127.06]
#> WELFARE HUMAN POLITICS
#> Min. [-229.94 : 138.29] [-879.71 : -501.15] [-491.78 : -70.01]
#> 1st Qu. [-184.41 : 161.36] [-726.36 : -312.15] [-346.20 : 66.67]
#> Median [-138.88 : 184.42] [-573.00 : -123.14] [-200.61 : 203.36]
#> Mean [92.63 : 92.63] [-352.28 : -352.28] [-63.41 : -63.41]
#> 3rd Qu. [-26.15 : 349.88] [-367.09 : 0.68] [-145.13 : 235.78]
#> Max. [86.57 : 515.34] [-161.18 : 124.50] [-89.65 : 268.21]
#> Std. [183.83 : 183.83] [295.23 : 295.23] [192.80 : 192.80]
#> BURDEN NOISE NATURE
#> Min. [-619.29 : -254.11] [-403.24 : -29.45] [-190.28 : 83.12]
#> 1st Qu. [-548.22 : -171.34] [-377.24 : -4.36] [-145.13 : 195.19]
#> Median [-477.14 : -88.57] [-351.24 : 20.72] [-99.99 : 307.27]
#> Mean [-282.90 : -282.90] [-152.88 : -152.88] [111.80 : 111.80]
#> 3rd Qu. [-423.03 : 11.05] [-294.80 : 52.49] [-33.02 : 422.00]
#> Max. [-368.92 : 110.66] [-238.37 : 84.26] [33.96 : 536.72]
#> Std. [166.31 : 166.31] [111.68 : 111.68] [181.34 : 181.34]
#> SEASETC MULTI WATERWASTE
#> Min. [-747.46 : -169.30] [-215.07 : 226.66] [-542.37 : -146.89]
#> 1st Qu. [-679.36 : -125.54] [-177.55 : 249.70] [-368.52 : 8.80]
#> Median [-611.26 : -81.79] [-140.04 : 272.75] [-194.66 : 164.49]
#> Mean [-262.66 : -262.66] [66.25 : 66.25] [-80.69 : -80.69]
#> 3rd Qu. [-367.73 : 38.11] [-97.46 : 290.42] [-157.59 : 260.17]
#> Max. [-124.20 : 158.01] [-54.88 : 308.08] [-120.52 : 355.84]
#> Std. [243.16 : 243.16] [121.64 : 121.64] [224.56 : 224.56]
#> VEHICLE
#> Min. [-840.00 : -574.57]
#> 1st Qu. [-754.88 : -405.27]
#> Median [-669.76 : -235.98]
#> Mean [-409.06 : -409.06]
#> 3rd Qu. [-437.21 : -82.68]
#> Max. [-204.67 : 70.63]
#> Std. [280.31 : 280.31]
#>
#> $symbolic_modal
#> URBANICITY INCOMELEVEL EDUCATION REGIONDEVELOPME
#> [1,] 6: 0.12 25: 0.54 1: 0.42 4: 0.51
#> [2,] 4: 0.45 75: 0.17 3: 0.57 3: 0.27
#> [3,] 5: 0.09 50: 0.18 5: 0.01 2: 0.15
#> [4,] 1: 0.20 90: 0.07 6: 0.00 1: 0.08
#> [5,] 3: 0.10 100: 0.04
#> [6,] 2: 0.05
ggInterval_indexplot(facedata, aes(x = AD, fill = Subjects)) +
scale_fill_brewer(palette = "Set1") +
geom_vline(xintercept = mean(facedata$AD), color = "darkgray") +
labs(fill = "Subjects")face.ip <- ggInterval_indexplot(facedata, aes(fill = Subjects), plotAll = TRUE) +
scale_fill_brewer(palette = "Set1") +
labs(x = "", y = "", fill = "Subjects")
face.ip
b <- ggInterval_indexplot(facedata, aes(fill = Subjects),
plotAll = TRUE, row_order = "c") +
scale_fill_brewer(palette = "Set1") +
labs(x = "", y = "", fill = "Subjects")
b
cc <- ggInterval_indexplot(facedata, aes(fill = Subjects),
plotAll = TRUE, row_order = "r") +
scale_fill_brewer(palette = "Set1") +
labs(x = "", y = "", fill = "Subjects")
ccIn the ordered plotAll displays, the outer y-axis labels
are suppressed by default. Here row_order = "c" reorders
observations by interval centers within each variable panel, while
row_order = "r" reorders them by interval ranges within
each variable panel. Set labels = TRUE if you want the row
labels repeated inside each variable panel.
The endpoint-quantile boxplots use the empirical 0%, 25%, 50%, 75%, and 100% quantiles of the lower endpoints and, separately, of the upper endpoints across observations. The side-by-side view shows the two endpoint summaries directly. These summaries do not identify the shape of a within-interval distribution. The widths of the quantile-box segments are heuristic display weights based on uniform interval-mass concentration, not an estimated within-interval density.
For the equal-bin histogram, breaks divide the pooled endpoint span
into bins equal parts. An interval of positive width
contributes its overlap length with a bin divided by its own width. This
allocation corresponds to uniform mass within each interval: weighted
frequencies sum to the number of observations, and relative frequencies
sum to one. A zero-width interval contributes one to exactly one bin.
Bins are left-closed and right-open, except that the final bin includes
the maximum endpoint. A constant variable uses a support padded on each
side by max(abs(value) * 0.05, 0.5).
The one-dimensional method = "unequal-bin" display has
different semantics. It counts how many intervals cover each location on
a 0.01 grid, joining consecutive equal counts into rectangles. Its table
calls this quantity Cumulative.Concepts; it is a coverage
count, not a probability mass or density. A constant variable is
represented by its coverage count at the exact value as a zero-width
rectangle, without grid construction or support padding. Isolated point
intervals can affect a coverage count only at sampled locations they
cover. The bins argument is ignored in this mode.
In 0.2.6 the first coverage run is encoded correctly when several
intervals share the minimum. For AD, this changes the first table row
from [149.35:150.32] 1 in 0.2.5 to
[149.34:150.32] 2; the positive-width equal-bin and 2D
overlap allocations are unchanged.
ggInterval_boxplot(facedata, plotAll = TRUE, width_type = "violin-like") +
theme(legend.position = "bottom", axis.text.x = element_blank())
ggInterval_boxplot(facedata, plotAll = TRUE, width_type = "side-by-side") +
theme(legend.position = "bottom", axis.text.x = element_blank())hist.obj.equal$`Table AD`
#> Interval Observed.Frequency Relative.Frequency
#> 1 [149.34:151.92] 1.077477 0.03990656
#> 2 [151.92:154.5] 1.753623 0.06494900
#> 3 [154.5:157.08] 5.525627 0.20465284
#> 4 [157.08:159.66] 2.806570 0.10394703
#> 5 [159.66:162.24] 1.042880 0.03862518
#> 6 [162.24:164.83] 1.703999 0.06311106
#> 7 [164.83:167.41] 3.304380 0.12238443
#> 8 [167.41:169.99] 4.948225 0.18326760
#> 9 [169.99:172.57] 3.738883 0.13847713
#> 10 [172.57:175.15] 1.098337 0.04067915
hist.obj.unequal <- ggInterval_hist(
facedata,
plotAll = TRUE,
method = "unequal-bin"
)
print(hist.obj.unequal)This example demonstrates the interval-valued line plot using the
built-in stock.data.LH table. It contains 62 observations
from January–March 1985 in the randomly generated TTR::ttrc
series, not prices of an actual security. It can be loaded without TTR
installed.
data("stock.data.LH", package = "ggInterval")
head(stock.data.LH)
#> # A tibble: 6 x 7
#> V1 Date Close Low High Month Day
#> <symblc_n> <date> <dbl> <dbl> <dbl> <fct> <int>
#> 1 [3.08 : 3.18] 1985-01-02 3.08 3.08 3.18 Jan 2
#> 2 [3.09 : 3.15] 1985-01-03 3.11 3.09 3.15 Jan 3
#> 3 [3.08 : 3.12] 1985-01-04 3.09 3.08 3.12 Jan 4
#> 4 [3.07 : 3.12] 1985-01-07 3.1 3.07 3.12 Jan 7
#> 5 [3.08 : 3.12] 1985-01-08 3.11 3.08 3.12 Jan 8
#> 6 [3.10 : 3.17] 1985-01-09 3.16 3.1 3.17 Jan 9V1 is the interval [Low, High]. The
accompanying columns are Date, Close,
Low, High, Month, and
Day. Month has levels Jan, Feb, and Mar, and
Day is the day of month. The interval center is
(Low + High) / 2; it need not equal the closing value
Close. The vertical ranges and connected centers preserve
daily low–high information, while the added points display the synthetic
closing values. No distribution of prices inside an interval is assumed
by this display. The free vertical scales support reading each monthly
panel; they do not provide a common visual scale for comparing vertical
changes between months. The connecting lines are descriptive, without
interpolation of unobserved daily paths, forecasting, or a
financial-performance interpretation.
ggInterval_lineplot(stock.data.LH, aes(y = V1, x = Day), barWidth = 0.6) +
geom_point(aes(y = Close), shape = 21, fill = "#D95F02",
color = "black", size = 1.6, stroke = 0.2) +
coord_cartesian(xlim = c(1, 31), expand = FALSE) +
facet_wrap(~Month, ncol = 1, scales = "free_y") +
scale_x_continuous(breaks = c(1, 8, 15, 22, 29)) +
labs(title = "Interval-valued Line Plot",
x = "Day of month", y = "Price") +
ggthemes::theme_economist() +
theme(strip.text = element_text(face = "bold"))The following code documents how the stored table was constructed. It is run only when TTR is installed; the source comparison uses TTR 0.24.4. The reconstructed object has a separate name so the example does not replace the built-in data.
data("ttrc", package = "TTR")
stock.data <- subset(
ttrc[, c("Date", "Close", "Low", "High")],
format(Date, "%Y-%m") %in% c("1985-01", "1985-02", "1985-03")
)
stock.data$Month <- factor(
month.abb[as.integer(format(stock.data$Date, "%m"))],
levels = month.abb[1:3]
)
stock.data$Day <- as.integer(format(stock.data$Date, "%d"))
stock.intervals <- classic2sym(
stock.data,
groupby = "customize",
minData = stock.data$Low,
maxData = stock.data$High
)$intervalData
stock.data.rebuilt <- dplyr::bind_cols(stock.intervals, stock.data)
head(stock.data.rebuilt)
#> # A tibble: 6 x 7
#> V1 Date Close Low High Month Day
#> <symblc_n> <date> <dbl> <dbl> <dbl> <fct> <int>
#> 1 [3.08 : 3.18] 1985-01-02 3.08 3.08 3.18 Jan 2
#> 2 [3.09 : 3.15] 1985-01-03 3.11 3.09 3.15 Jan 3
#> 3 [3.08 : 3.12] 1985-01-04 3.09 3.08 3.12 Jan 4
#> 4 [3.07 : 3.12] 1985-01-07 3.1 3.07 3.12 Jan 7
#> 5 [3.08 : 3.12] 1985-01-08 3.11 3.08 3.12 Jan 8
#> 6 [3.10 : 3.17] 1985-01-09 3.16 3.1 3.17 Jan 9mm.plot <- function(x) {
plot.var <<- names(facedata)[x]
ggInterval_MMplot(facedata, aes(facedata[[plot.var]], size = 2)) +
coord_fixed(ratio = 1) +
theme(legend.position = "none")
}
mm.plot.list <- lapply(seq_along(facedata), mm.plot)
gridExtra::marrangeGrob(mm.plot.list, nrow = 2, ncol = 3, top = "")ggInterval_scatterplot(
facedata,
aes(x = BC, y = AD, fill = Subjects),
showLabels = TRUE,
labelSize = 2.6,
labelPosition = "topright",
labelNudgeX = -0.2,
labelNudgeY = 0.15,
checkOverlap = FALSE,
color = "black"
) +
scale_fill_brewer(palette = "Set1") +
scale_x_continuous(expand = expansion(mult = c(0.08, 0.12))) +
scale_y_continuous(expand = expansion(mult = c(0.06, 0.10))) +
labs(fill = "Subjects")Both 2D methods allocate each observation’s mass as the product of
the two axis-overlap fractions. For positive-width intervals, this is
the product of uniform distributions within the observation’s rectangle.
display = "f" shows weighted frequencies, "p"
shows relative frequencies, and "h" shows relative
frequency divided by cell area. The relative frequencies sum to one; for
density, the sum of density times cell area is one. A point on an axis
is assigned to exactly one bin using the same boundary convention as the
equal-bin one-dimensional histogram.
Here method = "unequal-bin" uses sorted unique
endpoints, with tau merging chains of adjacent gaps smaller
than that tolerance while retaining the outer endpoints. It still
displays allocated mass or density, unlike the one-dimensional
unequal-bin coverage-count display. A constant axis is padded by the
same rule as above. Displayed table endpoints and values are rounded,
whereas allocation uses unrounded values.
face.2dh.equal <- ggInterval_2Dhist(
facedata,
aes(x = BC, y = AD, col = "white"),
method = "equal-bin",
xBins = 10,
yBins = 10,
display = "p",
palette = "Blues",
direction = 1,
cell_labels = TRUE
)$plot
face.2dh.equal +
coord_fixed(ratio = 1)face.2dh.unequal <- ggInterval_2Dhist(
facedata,
aes(x = BC, y = AD, col = "white"),
method = "unequal-bin",
display = "p",
palette = "Blues",
direction = 1,
tau = 0.5
)$plot
face.2dh.unequal +
coord_fixed(ratio = 1)ggInterval_2DhistMatrix(
facedata,
aes(col = "white"),
method = "equal-bin",
xBins = 10,
yBins = 10,
display = "p",
removeZero = TRUE,
palette = "Blues",
direction = 1,
cell_labels = FALSE
)ggInterval_2DhistMatrix(
facedata,
aes(col = "white"),
method = "unequal-bin",
display = "p",
palette = "Blues",
direction = 1,
tau = 0.5,
removeZero = TRUE,
cell_labels = FALSE
)ggInterval_indexImage(
facedata,
plotAll = TRUE,
full_strip = TRUE,
column_condition = FALSE
) +
scale_colour_distiller(palette = "Blues", direction = 1) +
labs(x = "Subjects") +
theme(axis.title.x = element_blank(),
axis.text.x = element_blank(),
axis.ticks.x = element_blank())
ggInterval_indexImage(
facedata,
plotAll = TRUE,
full_strip = TRUE
) +
scale_colour_distiller(palette = "Spectral") +
labs(x = "Subjects")
ggInterval_indexImage(
facedata,
plotAll = TRUE,
full_strip = FALSE,
column_condition = FALSE
) +
scale_colour_distiller(palette = "Blues", direction = 1) +
labs(x = "Subjects") +
theme(axis.title.x = element_blank(),
axis.text.x = element_blank(),
axis.ticks.x = element_blank())
ggInterval_indexImage(
facedata,
plotAll = TRUE,
full_strip = FALSE
) +
scale_colour_distiller(palette = "Spectral") +
labs(x = "Subjects")For the mixed Environment profiles, each interval axis
is normalized by that variable’s observed endpoint range over all 14
objects. Radial widths are therefore relative ranges, not directly
comparable raw widths across variables. Modal bars occupy the stored
category positions; their heights increase with the proportions but are
not proportional to them. The default polygon passes through the
largest-proportion category. The missing codebook described
above prevents label-specific interpretation.
The type = "quantile" examples pool lower and upper
endpoints for each interval variable. With quantileNum = q,
they retain empirical quantiles at \(k/(q+3)\) for \(k=1,\ldots,q+2\), round to two decimals,
and pair adjacent quantiles into \(q+1\) bands. Each axis is normalized over
its retained quantile range. These are adjacent pooled-endpoint bands,
not nested central-coverage intervals, confidence bands, or
distributions inside the individual intervals. They do not directly
compare absolute spread or establish skewness.
library(ggthemes)
ggInterval_radarplot(
Environment,
plotPartial = c(4, 6),
showLegend = FALSE,
base_circle = FALSE,
base_lty = 1,
addText = FALSE,
addText_modal = FALSE
) +
scale_fill_manual(values = c("darkred", "darkblue")) +
scale_color_manual(values = c("darkred", "darkblue")) +
labs(title = "") +
theme_hc()
ggInterval_radarplot(
Environment,
plotPartial = c(4, 6),
showLegend = FALSE,
base_circle = FALSE,
base_lty = 1,
addText = FALSE,
addText_modal = FALSE,
type = "rect"
) +
scale_fill_manual(values = c("darkred", "darkblue")) +
scale_color_manual(values = c("darkred", "darkblue")) +
labs(title = "") +
theme_hc()
ggInterval_radarplot(
facedata,
base_circle = FALSE,
base_lty = 1,
type = "quantile",
quantileNum = 5,
showLegend = TRUE,
Drift = 0
) +
scale_fill_brewer(palette = "Greys") +
labs(title = "", fill = "Quantiles") +
theme_hc()
ggInterval_radarplot(
Environment,
base_circle = FALSE,
base_lty = 1,
type = "quantile",
quantileNum = 5,
showLegend = TRUE,
Drift = 0
) +
scale_fill_brewer(palette = "Greys") +
labs(title = "", fill = "Quantiles") +
theme_hc()set.seed(1234567890)
facedata.tmp <- facedata
facedata.tmp$cluster <- RSDA::sym.kmeans(facedata.tmp, k = 3)$cluster
ggInterval_indexplot(facedata.tmp, aes(y = AD, fill = Subjects)) +
geom_text(
aes(x = seq_len(nrow(facedata.tmp)), y = .data$AD$min,
label = rownames(facedata.tmp)),
vjust = 1.5,
size = 2
) +
scale_fill_brewer(palette = "Set1") +
labs(title = "Customized Index Plot Using K-Means Clusters",
fill = "Subjects") +
facet_grid(cols = vars(cluster), scales = "free_x", space = "free_x") +
theme_economist_white() +
theme(axis.title.x = element_blank(),
axis.text.x = element_blank(),
axis.ticks.x = element_blank())This example is evaluated only when the optional package
HistDAWass is installed.
BLOOD <- HistDAWass::BLOOD
blood.min <- HistDAWass::get.MatH.stats(BLOOD, stat = "min")
blood.max <- HistDAWass::get.MatH.stats(BLOOD, stat = "max")
blood <- data.frame(blood.min, blood.max)
myBLOOD <- classic2sym(
blood,
groupby = "customize",
minData = blood[, 2:4],
maxData = blood[, 6:8]
)
colnames(myBLOOD$intervalData) <- HistDAWass::get.MatH.main.info(BLOOD)$varnames
ggInterval_PCA(myBLOOD$intervalData, plot = FALSE)$ggplotPCAThis example is evaluated only when the optional package
MAINT.Data is installed.
AbaloneIdt <- MAINT.Data::AbaloneIdt
AbaloneRange <- exp(AbaloneIdt@LogR)
AbaloneMid <- AbaloneIdt@MidP
AbaloneBounds <- data.frame(
AbaloneMid - AbaloneRange / 2,
AbaloneMid + AbaloneRange / 2
)
myAbalone <- classic2sym(
AbaloneBounds,
groupby = "customize",
minData = AbaloneBounds[, 1:7],
maxData = AbaloneBounds[, 8:14]
)
colnames(myAbalone$intervalData) <- AbaloneIdt@VarNames
ggInterval_PCA(myAbalone$intervalData, plot = FALSE)$ggplotPCAThese examples use vertex-based interval PCA. In
ggInterval_PCA(), vertex coordinates are standardized
column-wise before princomp; retained vertices receive
equal weight. This treats the vertices as the input to the projection,
without specifying a distribution inside each box. Projected intervals
and polygons describe geometric spread and overlap, not confidence
regions, recognition accuracy, or significance. The returned object is
an augmented princomp result; add graphical layers to
$ggplotPCA.
pca.results <- RSDA::sym.pca(facedata, method = "tops")
pca.results$Sym.Components <- structure(
as.data.frame(pca.results$Sym.Components),
class = c("symbolic_tbl", "data.frame"))
rownames(pca.results$Sym.Components) <- rownames(facedata)
ggInterval_scatterplot(
pca.results$Sym.Components,
aes(Dim.1, Dim.2, fill = as.factor(Subjects)),
labelSize = 2.6,
labelPosition = "topright",
labelNudgeX = -0.2,
labelNudgeY = 0.15,
checkOverlap = TRUE,
col = "black"
) +
scale_fill_brewer(palette = "Set1") +
scale_x_continuous(expand = expansion(mult = c(0.08, 0.12))) +
scale_y_continuous(expand = expansion(mult = c(0.06, 0.10))) +
coord_fixed(ratio = 1) +
labs(x = "PCA-1", y = "PCA-2", fill = "Subjects")
face.pca <- ggInterval_PCA(
facedata, poly = TRUE, concepts_group = as.factor(Subjects), plot = FALSE
)
face.pca$ggplotPCA +
coord_fixed(ratio = 1) +
labs(x = "PCA-1", y = "PCA-2")The heatmap below uses the package’s BG normalization described above. It is a heatmap of interval-center Pearson correlations, not the center–range association map introduced in the next section.
The following data reproduce the generating mechanism and seed used
in the paper’s simulation. They contain three groups of 15 bivariate
observations. Within each group, the two center coordinates have unit
generating variances and generating correlation 0.7, with means
(0, 0), (6, 5), and (-5, 6).
Independent half-widths are initially uniform on
[0.2, 0.9], [0.2, 1.4], and
[0.2, 1.9] for the three groups. Three selected
observations have both half-widths increased by 4; their centers are
unchanged. The generated data, not a newly tuned scenario, are shared by
all four diagnostic examples.
set.seed(20260709)
sim_interval <- function(n_per = 15, rho = 0.7,
mu = list(c(0, 0), c(6, 5), c(-5, 6)),
hw_lo = c(0.2, 0.2, 0.2),
hw_hi = c(0.9, 1.4, 1.9),
outlier_frac = 0.06) {
G <- length(mu)
Sigma <- matrix(c(1, rho, rho, 1), 2, 2)
rows <- list()
for (g in seq_len(G)) {
C <- MASS::mvrnorm(n_per, mu = mu[[g]], Sigma = Sigma)
h1 <- runif(n_per, hw_lo[g], hw_hi[g])
h2 <- runif(n_per, hw_lo[g], hw_hi[g])
df <- data.frame(
group = factor(g),
X1min = C[, 1] - h1, X1max = C[, 1] + h1,
X2min = C[, 2] - h2, X2max = C[, 2] + h2)
rows[[g]] <- df
}
dat <- do.call(rbind, rows)
# Move both endpoints outward by 4; preserve the centers.
n_out <- max(1, round(outlier_frac * nrow(dat)))
idx <- sample(seq_len(nrow(dat)), n_out)
dat$X1min[idx] <- dat$X1min[idx] - 4; dat$X1max[idx] <- dat$X1max[idx] + 4
dat$X2min[idx] <- dat$X2min[idx] - 4; dat$X2max[idx] <- dat$X2max[idx] + 4
dat$outlier <- FALSE; dat$outlier[idx] <- TRUE
dat
}
sim <- sim_interval()
sim.sym <- classic2sym(sim, groupby = "customize",
minData = sim[, c("X1min", "X2min")],
maxData = sim[, c("X1max", "X2max")])$intervalData
colnames(sim.sym) <- c("X1", "X2")
which(sim$outlier)
#> [1] 6 10 39
centers <- data.frame(group = sim$group,
X1 = (sim$X1min + sim$X1max) / 2,
X2 = (sim$X2min + sim$X2max) / 2)
round(c(pooled = stats::cor(centers$X1, centers$X2),
sapply(split(centers, centers$group),
function(d) stats::cor(d$X1, d$X2))), 3)
#> pooled 1 2 3
#> -0.082 0.857 0.890 0.647The injected rows are 6, 10, and 39. The within-group sample correlations are approximately 0.86, 0.89, and 0.65; the pooled sample correlation is approximately -0.08. The latter also reflects differences among group means. Neither the generating correlation nor these sample correlations is an intraclass correlation or a measure of agreement between study centers. Here an interval center simply means its midpoint.
head(attr(p.ecdf, "interval_diagnostics")$knots)
#> variable x lower_cdf upper_cdf
#> 1 X1 -9.030983 0 0.02222222
#> 2 X1 -7.335504 0 0.04444444
#> 3 X1 -7.163186 0 0.06666667
#> 4 X1 -7.111917 0 0.08888889
#> 5 X1 -6.673280 0 0.11111111
#> 6 X1 -6.600082 0 0.13333333The lower curve is the empirical CDF of the upper endpoints and the upper curve is the empirical CDF of the lower endpoints. Every empirical CDF formed by selecting one value per interval lies between them, with equal observation weights. Steps and shaded rectangles use exact endpoint knots; the dashed line is the midpoint ECDF. This is an endpoint envelope, not a confidence band or an estimated within-interval distribution.
association <- attr(p.association, "interval_diagnostics")
round(association$pooled, 3)
#> C1 C2 R1 R2
#> C1 1.000 -0.082 -0.143 -0.152
#> C2 -0.082 1.000 0.074 0.009
#> R1 -0.143 0.074 1.000 0.863
#> R2 -0.152 0.009 0.863 1.000
round(association$group_demeaned, 3)
#> C1 C2 R1 R2
#> C1 1.000 0.796 0.122 0.096
#> C2 0.796 1.000 0.016 0.012
#> R1 0.122 0.016 1.000 0.861
#> R2 0.096 0.012 0.861 1.000For each variable this display derives a center column C
and a full-range column R. The lower-left triangle contains
ordinary Pearson correlations pooled over observations. With
group supplied, the upper-right triangle uses residuals
after removing each group’s mean from each derived column. The diagonal
contains pooled self-correlations. This juxtaposition helps separate
pooled associations from associations after group-mean removal; the
assembled display is not a single correlation matrix.
Group-demeaned correlations are not averages of group-specific
correlations, ICCs, inter-center agreement measures, or the B, BD, or BG
interval correlations. A constant derived column has undefined
correlation, shown as NA. Group labels are supplied
information, not estimated clusters.
p.deviation <- ggInterval_deviation(
sim.sym, group = sim$group, highlight = sim$outlier
)
p.deviationhead(attr(p.deviation, "interval_diagnostics")$contributions)
#> id group center range total highlighted
#> 1 1 1 0.008571352 2.507826e-04 0.008822135 FALSE
#> 2 2 1 0.008354644 3.007811e-05 0.008384723 FALSE
#> 3 3 1 0.004407537 1.076087e-03 0.005483624 FALSE
#> 4 4 1 0.023357724 1.363128e-05 0.023371355 FALSE
#> 5 5 1 0.005543840 7.157982e-04 0.006259639 FALSE
#> 6 6 1 0.001610514 1.106980e-01 0.112308528 TRUEThe default reference comprises componentwise medians of the centers and full ranges within each supplied group; the default scale for each variable is its global endpoint span. With center difference \(\Delta c_j\), full-range difference \(\Delta r_j\), and positive scale \(s_j\), the two contributions are \(\sum_j(\Delta c_j/s_j)^2\) and \(\sum_j(\Delta r_j/(2s_j))^2\). Their sum equals the mean squared standardized deviation of the two endpoints, summed over variables.
Bars are ordered by total deviation and retain every observation. Outlined bars identify the supplied injection labels; the function does not detect outliers. This is a geometric decomposition, not a Shapley attribution or a calibrated test. Values depend on the chosen reference and scales, so a large bar should be interpreted with its center and range contributions.
attr(p.overlap, "interval_diagnostics")$overlap[1:5, 1:5]
#> 1 2 3 4 5
#> 1 1.000000000 0.16074251 0.008384434 0.00000000 0
#> 2 0.160742508 1.00000000 0.154952193 0.04834752 0
#> 3 0.008384434 0.15495219 1.000000000 0.00000000 0
#> 4 0.000000000 0.04834752 0.000000000 1.00000000 0
#> 5 0.000000000 0.00000000 0.000000000 0.00000000 1Each observation is the Cartesian product of its selected intervals. A cell shows intersection volume divided by union volume: zero for disjoint boxes or mere boundary contact and one for identical positive-volume boxes. Grouping changes the display order, not the overlaps. This compares observations geometrically; it is not a variable-correlation heatmap or a measure of agreement between unobserved within-box distributions.
Any box with zero width on a selected axis has zero volume. The
default zero_width = "error" rejects this case;
zero_width = "na" marks every pair involving that box as
missing, including its diagonal. It does not assign artificial zero or
perfect overlap to degenerate boxes.
Use citation("ggInterval") after installation to
retrieve the current package citation metadata.
sessionInfo()
#> R version 4.6.1 (2026-06-24 ucrt)
#> Platform: x86_64-w64-mingw32/x64
#> Running under: Windows 11 x64 (build 26300)
#>
#> Matrix products: default
#> LAPACK version 3.12.1
#>
#> locale:
#> [1] C
#> system code page: 65001
#>
#> time zone: Asia/Taipei
#> tzcode source: internal
#>
#> attached base packages:
#> [1] stats graphics grDevices utils datasets methods base
#>
#> other attached packages:
#> [1] RSQLite_3.53.3 ggthemes_7.0.0 ggInterval_0.2.6 RSDA_3.2.5
#> [5] lubridate_1.9.5 forcats_1.0.1 stringr_1.6.0 dplyr_1.2.1
#> [9] purrr_1.2.2 readr_2.2.0 tidyr_1.3.2 tibble_3.3.1
#> [13] tidyverse_2.0.0 ggplot2_4.0.3
#>
#> loaded via a namespace (and not attached):
#> [1] neuralnet_1.44.2 splines_4.6.1 polyclip_1.10-7
#> [4] xts_0.14.3 XML_3.99-0.25 rpart_4.1.27
#> [7] lifecycle_1.0.5 tcltk_4.6.1 rstatix_1.1.0
#> [10] globals_0.20.0 lattice_0.22-9 MASS_7.3-65
#> [13] flashClust_1.1-4 backports_1.5.1 magrittr_2.0.5
#> [16] plotly_4.12.1 sass_0.4.10 rmarkdown_2.32
#> [19] jquerylib_0.1.4 yaml_2.3.12 otel_0.2.0
#> [22] sn_2.1.3 askpass_1.2.1 reticulate_1.47.0
#> [25] DBI_1.3.0 RColorBrewer_1.1-3 abind_1.4-8
#> [28] Rtsne_0.17 tweenr_2.0.3 lava_1.10
#> [31] gbm_2.3.1 ggrepel_0.9.8 irlba_2.4.1
#> [34] listenv_1.1.0 proto_1.0.0 umap_0.2.10.0
#> [37] RSpectra_0.16-2 parallelly_1.50.0 codetools_0.2-20
#> [40] DT_0.34.0 ggforce_0.5.0 tidyselect_1.2.1
#> [43] shape_1.4.6.1 farver_2.1.2 stats4_4.6.1
#> [46] showtext_0.9-8 jsonlite_2.0.0 Formula_1.2-6
#> [49] ggridges_0.5.7 randomcoloR_1.1.0.1 survival_3.8-6
#> [52] iterators_1.0.14 emmeans_2.0.4 HistDAWass_1.0.10
#> [55] foreach_1.5.2 tools_4.6.1 chron_2.3-63
#> [58] miscTools_0.6-30 Rcpp_1.1.2 glue_1.8.1
#> [61] mnormt_2.1.2 prodlim_2026.03.11 gridExtra_2.3.1
#> [64] xfun_0.62 TTR_0.24.4 numDeriv_2016.8-1.1
#> [67] withr_3.0.3 fastmap_1.2.0 GGally_2.4.0
#> [70] openssl_2.5.0 digest_0.6.39 timechange_0.4.0
#> [73] R6_2.6.1 estimability_2.0.0 colorspace_2.1-4
#> [76] gtools_3.9.5 MAINT.Data_2.8.0 ggpolypath_0.4.0
#> [79] utf8_1.2.6 generics_0.1.4 data.table_1.18.6.1
#> [82] robustbase_0.99-7 class_7.3-23 httr_1.4.9
#> [85] htmlwidgets_1.6.4 scatterplot3d_0.3-45 sqldf_0.4-12
#> [88] ggstats_0.14.0 RJSONIO_2.0.5 pkgconfig_2.0.3
#> [91] gtable_0.3.6 blob_1.3.0 S7_0.2.2
#> [94] pcaPP_2.0-7 htmltools_0.5.9 carData_3.0-6
#> [97] sysfonts_0.8.9 multcompView_0.1-12 scales_1.4.0
#> [100] leaps_3.2 png_0.1-9 histogram_0.0-25
#> [103] knitr_1.52 tzdb_0.5.0 curl_8.1.0
#> [106] nloptr_2.2.1 showtextdb_3.0 cachem_1.1.0
#> [109] zoo_1.9-1 parallel_4.6.1 pillar_1.11.1
#> [112] grid_4.6.1 reshape_0.8.10 vctrs_0.7.3
#> [115] randomForest_4.7-1.2 ggpubr_1.0.0 car_3.1-5
#> [118] xtable_1.8-8 cluster_2.1.8.2 princurve_2.1.6
#> [121] evaluate_1.0.5 gsubfn_0.7 mvtnorm_1.4-2
#> [124] cli_3.6.6 compiler_4.6.1 rlang_1.3.0
#> [127] rrcov_1.7-7 future.apply_1.21.0 ggsignif_0.6.4
#> [130] labeling_0.4.3 mclust_6.1.3 plyr_1.8.9
#> [133] stringi_1.8.9 viridisLite_0.4.3 glmnet_5.2
#> [136] V8_8.2.1 Matrix_1.7-5 hms_1.1.4
#> [139] bit64_4.8.6 future_1.82.0 FactoMineR_2.18
#> [142] kknn_1.4.1 igraph_2.3.4 broom_1.0.13
#> [145] memoise_2.0.1 bslib_0.12.0 DEoptimR_1.2-2
#> [148] bit_4.6.0