getColorDistanceMatrix: Distance matrix for a list of color cluster sets

Description Usage Arguments Details Value Examples

View source: R/04_comparison_metrics.R

Description

Calculates a distance matrix for a list of color cluster sets as returned by extractClusters or getHistList based on the specified distance metric.

Usage

1
2
3
4
5
6
7
8
9
getColorDistanceMatrix(
  cluster.list,
  method = "emd",
  ordering = "default",
  size.weight = 0.5,
  color.weight = 0.5,
  plotting = TRUE,
  ...
)

Arguments

cluster.list

A list of identically sized dataframes with 4 columns each (R, G, B, Pct or H, S, V, Pct) as output by extractClusters or getHistList.

method

One of four possible comparison methods for calculating the color distances: "emd" (uses EMDistance, recommended), "chisq" (uses chisqDistance), "color.dist" (uses colorDistance; not appropriate if binAvg=F), or "weighted.pairs" (weightedPairsDistance).

ordering

Logical if not left as "default". Should the color clusters in the list be reordered to minimize the distances between the pairs? If left as default, ordering depends on distance method: "emd" and "chisq" do not order clusters ("emd" orders on a case-by-case in the EMDistance function itself and reordering by size similarity would make chi-squared meaningless); "color.dist" and "weighted.pairs" use ordering. To override defaults, set to either T (for ordering) or F (for no ordering).

size.weight

Same as in weightedPairsDistance.

color.weight

Same as in weightedPairsDistance.

plotting

Logical. Should a heatmap of the distance matrix be displayed once the function finishes running?

...

Additional arguments passed on to heatmapColorDistance.

Details

Each cell represents the distance between a pair of color cluster sets as measured using either chi-squared distance (cluster size only), earth mover's distance (size and color), weighted pairs (size and color with user-specified weights for each), or color distance (Euclidean distance between clusters as 3-dimensional - RGB or HSV - color coordinates).

Earth mover's distance is recommended unless binAvg is set to false during cluster list generation (in which case all paired bins will have the same colors across datasets), in which case chi-squared is recommended. Weighted pairs or color distance may be appropriate depending on the question, but generally give poorer results.

Value

A distance matrix of image distance scores (the scales vary depending on the distance metric chosen, but for all four methods, higher scores = more different).

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
## Not run: 
cluster.list <- colordistance::getHistList(c(system.file("extdata",
"Heliconius/Heliconius_A", package="colordistance"), system.file("extdata",
"Heliconius/Heliconius_B", package="colordistance")), lower=rep(0.8, 3),
upper=rep(1, 3))

# Default values - recommended!
colordistance::getColorDistanceMatrix(cluster.list, main="EMD")

# Without plotting
colordistance::getColorDistanceMatrix(cluster.list, plotting=FALSE)

# Use chi-squared instead
colordistance::getColorDistanceMatrix(cluster.list, method="chisq", main="Chi-squared")

# Override ordering (throws a warning if you're trying to do this with
# chisq!)
colordistance::getColorDistanceMatrix(cluster.list, method="chisq",
ordering=TRUE, main="Chi-squared w/ ordering")

# Specify high size weight/low color weight for weighted pairs
colordistance::getColorDistanceMatrix(cluster.list, method="weighted.pairs",
color.weight=0.1, size.weight=0.9, main="Weighted pairs")

# Color distance only
colordistance::getColorDistanceMatrix(cluster.list, method="color.dist",
ordering=TRUE, main="Color distance only")

## End(Not run)

Example output

Using 3^3 = 27 total bins

  |                                                                            
  |                                                                      |   0%
  |                                                                            
  |=========                                                             |  12%
  |                                                                            
  |==================                                                    |  25%
  |                                                                            
  |==========================                                            |  38%
  |                                                                            
  |===================================                                   |  50%
  |                                                                            
  |============================================                          |  62%
  |                                                                            
  |====================================================                  |  75%
  |                                                                            
  |=============================================================         |  88%
  |                                                                            
  |======================================================================| 100%              Heliconius_01 Heliconius_02 Heliconius_03 Heliconius_04
Heliconius_01            NA     0.2182759     0.3061009     0.1205113
Heliconius_02     0.2182759            NA     0.1175362     0.1836246
Heliconius_03     0.3061009     0.1175362            NA     0.2358114
Heliconius_04     0.1205113     0.1836246     0.2358114            NA
Heliconius_05     0.1567979     0.3601333     0.4128249     0.1902837
Heliconius_06     0.1559977     0.3512470     0.4186883     0.1876346
Heliconius_07     0.1604639     0.3639967     0.4079450     0.1882325
Heliconius_08     0.1948497     0.3924887     0.4640629     0.2349924
              Heliconius_05 Heliconius_06 Heliconius_07 Heliconius_08
Heliconius_01    0.15679792    0.15599774    0.16046391    0.19484967
Heliconius_02    0.36013329    0.35124701    0.36399665    0.39248866
Heliconius_03    0.41282493    0.41868830    0.40794498    0.46406290
Heliconius_04    0.19028367    0.18763465    0.18823245    0.23499238
Heliconius_05            NA    0.08913072    0.03418941    0.11085261
Heliconius_06    0.08913072            NA    0.07959062    0.06253095
Heliconius_07    0.03418941    0.07959062            NA    0.10215050
Heliconius_08    0.11085261    0.06253095    0.10215050            NA
              Heliconius_01 Heliconius_02 Heliconius_03 Heliconius_04
Heliconius_01            NA     0.2182759     0.3061009     0.1205113
Heliconius_02     0.2182759            NA     0.1175362     0.1836246
Heliconius_03     0.3061009     0.1175362            NA     0.2358114
Heliconius_04     0.1205113     0.1836246     0.2358114            NA
Heliconius_05     0.1567979     0.3601333     0.4128249     0.1902837
Heliconius_06     0.1559977     0.3512470     0.4186883     0.1876346
Heliconius_07     0.1604639     0.3639967     0.4079450     0.1882325
Heliconius_08     0.1948497     0.3924887     0.4640629     0.2349924
              Heliconius_05 Heliconius_06 Heliconius_07 Heliconius_08
Heliconius_01    0.15679792    0.15599774    0.16046391    0.19484967
Heliconius_02    0.36013329    0.35124701    0.36399665    0.39248866
Heliconius_03    0.41282493    0.41868830    0.40794498    0.46406290
Heliconius_04    0.19028367    0.18763465    0.18823245    0.23499238
Heliconius_05            NA    0.08913072    0.03418941    0.11085261
Heliconius_06    0.08913072            NA    0.07959062    0.06253095
Heliconius_07    0.03418941    0.07959062            NA    0.10215050
Heliconius_08    0.11085261    0.06253095    0.10215050            NA
              Heliconius_01 Heliconius_02 Heliconius_03 Heliconius_04
Heliconius_01            NA     0.2536757     0.3297508     0.1086816
Heliconius_02     0.2536757            NA     0.1380965     0.1874185
Heliconius_03     0.3297508     0.1380965            NA     0.1736454
Heliconius_04     0.1086816     0.1874185     0.1736454            NA
Heliconius_05     0.1345356     0.6196118     0.5311528     0.2365680
Heliconius_06     0.2952397     0.6853342     0.7479771     0.3036536
Heliconius_07     0.2166752     0.7071544     0.6331920     0.3043374
Heliconius_08     0.3244873     0.7496441     0.8181894     0.3591380
              Heliconius_05 Heliconius_06 Heliconius_07 Heliconius_08
Heliconius_01    0.13453560    0.29523971    0.21667515    0.32448732
Heliconius_02    0.61961182    0.68533424    0.70715440    0.74964412
Heliconius_03    0.53115278    0.74797708    0.63319199    0.81818936
Heliconius_04    0.23656803    0.30365360    0.30433744    0.35913797
Heliconius_05            NA    0.21803707    0.04652444    0.23004669
Heliconius_06    0.21803707            NA    0.13430362    0.01143778
Heliconius_07    0.04652444    0.13430362            NA    0.15135721
Heliconius_08    0.23004669    0.01143778    0.15135721            NA
              Heliconius_01 Heliconius_02 Heliconius_03 Heliconius_04
Heliconius_01            NA     0.2536085     0.3297508     0.1086816
Heliconius_02     0.2536085            NA     0.1380965     0.1874185
Heliconius_03     0.3297508     0.1380965            NA     0.1736454
Heliconius_04     0.1086816     0.1874185     0.1736454            NA
Heliconius_05     0.1345356     0.6195413     0.5311528     0.2365680
Heliconius_06     0.2952397     0.6852644     0.7479771     0.3036536
Heliconius_07     0.2166752     0.7070842     0.6331920     0.3043374
Heliconius_08     0.3244873     0.7496441     0.8181894     0.3591380
              Heliconius_05 Heliconius_06 Heliconius_07 Heliconius_08
Heliconius_01    0.13453560    0.29523971    0.21667515    0.32448732
Heliconius_02    0.61954134    0.68526439    0.70708424    0.74964412
Heliconius_03    0.53115278    0.74797708    0.63319199    0.81818936
Heliconius_04    0.23656803    0.30365360    0.30433744    0.35913797
Heliconius_05            NA    0.21803707    0.04652444    0.23004669
Heliconius_06    0.21803707            NA    0.13430362    0.01143778
Heliconius_07    0.04652444    0.13430362            NA    0.15135721
Heliconius_08    0.23004669    0.01143778    0.15135721            NA
Warning message:
In colordistance::getColorDistanceMatrix(cluster.list, method = "chisq",  :
  Setting ordering = T for 'chisq' method not recommended (comparisons may not be valid)
              Heliconius_01 Heliconius_02 Heliconius_03 Heliconius_04
Heliconius_01            NA      2.161796      3.535338      2.894014
Heliconius_02      2.161796            NA      3.929224      3.307333
Heliconius_03      3.535338      3.929224            NA      2.662727
Heliconius_04      2.894014      3.307333      2.662727            NA
Heliconius_05      3.602842      4.179060      4.990695      3.774216
Heliconius_06      3.071438      3.512737      4.246948      3.027724
Heliconius_07      2.635319      3.940605      3.506454      2.856791
Heliconius_08      2.904458      4.061058      3.107797      2.142971
              Heliconius_05 Heliconius_06 Heliconius_07 Heliconius_08
Heliconius_01      3.602842      3.071438      2.635319      2.904458
Heliconius_02      4.179060      3.512737      3.940605      4.061058
Heliconius_03      4.990695      4.246948      3.506454      3.107797
Heliconius_04      3.774216      3.027724      2.856791      2.142971
Heliconius_05            NA      2.888712      2.461035      3.417288
Heliconius_06      2.888712            NA      2.129609      2.332598
Heliconius_07      2.461035      2.129609            NA      1.826989
Heliconius_08      3.417288      2.332598      1.826989            NA
Warning messages:
1: In plot.window(...) : "color.weight" is not a graphical parameter
2: In plot.window(...) : "size.weight" is not a graphical parameter
3: In plot.xy(xy, type, ...) : "color.weight" is not a graphical parameter
4: In plot.xy(xy, type, ...) : "size.weight" is not a graphical parameter
5: In title(...) : "color.weight" is not a graphical parameter
6: In title(...) : "size.weight" is not a graphical parameter
              Heliconius_01 Heliconius_02 Heliconius_03 Heliconius_04
Heliconius_01            NA      1.024176     1.3736938     1.3685949
Heliconius_02      1.024176            NA     2.1063542     2.1641344
Heliconius_03      1.373694      2.106354            NA     0.9169152
Heliconius_04      1.368595      2.164134     0.9169152            NA
Heliconius_05      2.053400      2.848632     2.0706696     1.4590219
Heliconius_06      1.774129      2.240097     1.7410713     1.6303543
Heliconius_07      1.704659      2.502290     1.6671533     1.6078191
Heliconius_08      1.791225      2.602836     1.3632108     1.2104326
              Heliconius_05 Heliconius_06 Heliconius_07 Heliconius_08
Heliconius_01      2.053400     1.7741294     1.7046587     1.7912249
Heliconius_02      2.848632     2.2400974     2.5022899     2.6028364
Heliconius_03      2.070670     1.7410713     1.6671533     1.3632108
Heliconius_04      1.459022     1.6303543     1.6078191     1.2104326
Heliconius_05            NA     1.5554628     1.0586443     1.5360263
Heliconius_06      1.555463            NA     0.7997668     0.7370285
Heliconius_07      1.058644     0.7997668            NA     0.9075509
Heliconius_08      1.536026     0.7370285     0.9075509            NA

colordistance documentation built on March 21, 2021, 1:06 a.m.