commit cf2b7e681340ad6e3b9e040b9ca9e57a6b0ee4f9
parent 53ec0626fea9a977460cc332ba88d1df56a11679
Author: Eamon Caddigan <eamon.caddigan@gmail.com>
Date: Wed, 8 Sep 2021 07:06:03 -0400
Fixed an indexing error, I think.
Diffstat:
3 files changed, 9 insertions(+), 8 deletions(-)
diff --git a/demo.Rmd b/demo.Rmd
@@ -19,6 +19,7 @@ library(grDevices)
source('dissimilarity.R')
source('seq_dissim_colors.R')
source('color_utils.R')
+set.seed(271191508)
```
```{r}
compare_colors <- function(cols, cvd_function = identity) {
@@ -32,10 +33,10 @@ Next let's grab some random colors and show them.
```{r}
some_colors <- c('red', 'black', 'white', 'khaki', 'gray50',
'#a6cee3', '#1f78b4', '#b2df8a', '#33a02c')
-some_colors <- paste0("gray", round(seq(10, 90, length.out = 13)))
-some_colors <- colorRampPalette(c("gray10", "gray90"), space = "Lab")(6)
+#some_colors <- paste0("gray", round(seq(10, 90, length.out = 13)))
+#some_colors <- colorRampPalette(c("gray10", "gray90"), space = "Lab")(6)
some_colors <- sample(some_colors)
-compare_colors(some_colors)
+colorspace::swatchplot(some_colors)
```
Here's the mild deuteranomaly we're using for the default color comparison (it's more extreme than my own).
diff --git a/dissimilarity.R b/dissimilarity.R
@@ -75,9 +75,9 @@ cvd_dissimilarity <- function(cols, cvd = "deuteranomaly") {
}
# Apply the transformation and get the dissimilarity matrix
- dist_mat <- lab_dist(apply_cvd(col2RGB(cols), cvd_fn))
- colnames(dist_mat) <- cols
- rownames(dist_mat) <- cols
+ dissim_mat <- lab_dist(apply_cvd(col2RGB(cols), cvd_fn))
+ colnames(dissim_mat) <- cols
+ rownames(dissim_mat) <- cols
- dist_mat
+ dissim_mat
}
diff --git a/seq_dissim_colors.R b/seq_dissim_colors.R
@@ -14,7 +14,7 @@ seq_dissim_colors <- function(dissim_mat) {
# First, we'll find the column that has the pair of colors with the maximum
# dissimilarity and save that column as the "first" color we picked and store
# this column as a vector.
- color_sequence[1] <- which.max(dissim_mat) %/% nrow(dissim_mat)
+ color_sequence[1] <- which.max(dissim_mat) %/% nrow(dissim_mat) + 1
dissim_vec <- dissim_mat[, color_sequence[1]]
for (i in seq(2, length(dissim_vec))) {