Справочный пост, Учитывая конечный палитра, как сортировать от горячего к холодному, т.е. расходящиеся
Я пытаюсь понять машинное обучение в R на основе этого руководства, https://machinelearningmastery.com/machine-learning-in-r-step-by-step/. К сожалению, я не знаю, как использовать это для сортировки цветов от горячих к холодным.
В конце поста есть мой код
я пытаюсь разобраться в этом
[1] "#22325f" "#88ce64" "#fbd234" "#b8091f" "#682f4e" "#fdea6e" "#4aec6a" "#fb7894" "#f13111" "#2584a0"
[11] "#460809" "#00699e" "#391b72" "#03471d" "#ba0841"
В это
[1] "#391b72" "#22325f" "#03471d" "#00699e" "#2584a0" "#4aec6a" "#88ce64" "#fdea6e" "#fbd234" "#fb7894"
[11] "#f13111" "#b8091f" "#ba0841" "#682f4e" "#460809"
Но вместо этого я получаю это (случайные темные полосы особенно неприятны).
ПОМОЩЬ!!!
[1] "#391b72" "#22325f" "#00699e" "#2584a0" "#03471d" "#4aec6a" "#88ce64" "#fdea6e" "#fbd234" "#f13111"
[11] "#460809" "#b8091f" "#fb7894" "#ba0841" "#682f4e"
КОД
RenderPal <- function(x,name){
if ((missing(x)) || (missing(name))){
stop("Internal error, please troubleshoot")
}
n <- length(x)
old <- graphics::par(mar = c(0.5, 0.5, 0.5, 0.5))
on.exit(graphics::par(old))
graphics::image(1:n, 1, as.matrix(1:n), col = x,
ylab = "", xaxt = "n", yaxt = "n", bty = "n")
graphics::rect(0, 0.9, n + 1, 1.1, col = grDevices::rgb(1, 1, 1, 0.8), border = NA)
graphics::text((n + 1) / 2, 1, labels = name, cex = 2, family = "serif")
}
i <- NULL
oldPal <- NULL
rankorder <- c(1,2,3,4,5,6,7,8,9,10,11)
orderedPal<- NULL
RGBcol <- NULL
HSVcol <- NULL
tHSVcol <- NULL
orderType <- "Unsorted"
#oldPal <- c("#313695","#fdae61","#a50026","#ffffbf","#f46d43","#fee090","#e0f3f8","#74add1","#d73027","#4575b4","#abd9e9")
oldPal <- c("#22325f", "#88ce64", "#fbd234", "#b8091f", "#682f4e", "#fdea6e", "#4aec6a", "#fb7894", "#f13111", "#2584a0", "#460809", "#00699e", "#391b72", "#03471d", "#ba0841")
# Print hex values
oldPal
# Convert Hex to RGB
RGBcol <- col2rgb(oldPal)
# Print RGB values
RGBcol
# Transpose matrix
tRGBcol <- t(RGBcol)
# Print matrix
tRGBcol
# Convert RGB to HSV
HSVcol <- rgb2hsv(RGBcol)
# Print matrix
HSVcol
# Transpose matrix
tHSVcol <- t(HSVcol)
# Print matrix
tHSVcol
hLIM <- rgb2hsv(col2rgb('#8000ff'))['h', ]
sLIM <- rgb2hsv(col2rgb('#8000ff'))['s', ]
vLIM <- rgb2hsv(col2rgb('#8000ff'))['v', ]
rankorder <- order((hLIM-tHSVcol[,1] + (hLIM < tHSVcol[,1])),
(sLIM-tHSVcol[,2] + (sLIM < tHSVcol[,2])),
(vLIM-tHSVcol[,3] + (vLIM < tHSVcol[,3])))
orderType <- "HSV Ordering"
rankorder
for (i in 1:length(rankorder)){
orderedPal[i] <- oldPal[rankorder[i]]
}
# Print old, unordered palette
oldPal
# Print new, ordered palette
orderedPal
RenderPal(oldPal, "Unordered Palette")
RenderPal(orderedPal, orderType)