rmaia / pavo

tools for the analysis of color data in R
http://pavo.colrverse.com
GNU General Public License v2.0
68 stars 17 forks source link

Simplify `jnd2xyz()` with `base::cmdscale()` #230

Open Bisaloo opened 3 years ago

Bisaloo commented 3 years ago

We talking about this but opening an issue here for memory and in case someone wants to chime in:

library(pavo)
#> Welcome to pavo 2! Take a look at the latest features (and update your bibliography) in our recent publication: Maia R., Gruson H., Endler J. A., White T. E. (2019) pavo 2: new tools for the spectral and spatial analysis of colour in R. Methods in Ecology and Evolution, 10, 1097-1107.

data(flowers)
vis.flowers <- vismodel(flowers, visual = "apis")
cd.flowers <- coldist(vis.flowers, n = c(1,1,1))
#> Quantum catch are relative, distances may not be meaningful
#> Calculating noise-weighted Euclidean distances

# Current method
pavo_xyz <- jnd2xyz(cd.flowers)
plot(pavo_xyz, asp = 1)

# Base method
base_xyz <- cmdscale(coldist2mat(cd.flowers)[[1]], k = 2)
plot(base_xyz[, 1], base_xyz[, 2], asp = 1)

# Base method only rotates the output compared to the current method
base_xyz <- base_xyz * -1
plot(pavo_xyz, asp = 1)
plot(base_xyz[, 1], base_xyz[, 2], asp = 1)

Created on 2021-04-27 by the reprex package (v2.0.0.9000)

Bisaloo commented 3 years ago

As Tom mentioned, we now need to figure out how we can transpose the current rotational options with the framework proposed in this issue.