【发布时间】:2021-11-23 22:21:42
【问题描述】:
我想为世界颜色调查使用的芯片制作孟塞尔颜色图表。它应该是这样的:
需要的信息可以在WCS页面here找到,我采取以下步骤:
library(munsell) # https://cran.r-project.org/web/packages/munsell/munsell.pdf
library(ggplot2)
# take the "cnum-vhcm-lab-new.txt" file from: https://www1.icsi.berkeley.edu/wcs/data.html#wmt
# change by replacing .50 with .5 removing .00 after hue values
WCS <- read.csv("cnum-vhcm-lab-new.txt", sep = "\t", header = T)
WCS$hex <- mnsl2hex(hvc2mnsl(hue = WCS$MunH, value = ceiling(WCS$MunV), chroma = WCS$C), fix = T)
# this works, but the order of tiles is messed up
ggplot(aes(x=H, y=V, fill=hex), data = WCS) +
geom_tile(aes(x=H, y=V), show.legend = F) +
scale_fill_manual(values = WCS$hex) +
scale_x_continuous(breaks = scales::pretty_breaks(n = 40))
结果:
显然,芯片不是按照色调和值排序,而是参考其他维度,甚至可能在原始数据框中排序。我还必须恢复 y 轴上的顺序。我想解决方案将与factor() 和reorder() 有关,但是怎么做呢?
【问题讨论】:
-
您能否提供“通过删除色调值后的 .5 和 .00 进行更改”的代码?我不断收到错误。
-
嗨布赖恩,只是在文本编辑或类似的情况下,在阅读 R 中的文件之前。查找和替换,实际上我没有正确输入,它应该是 .50 > .5 和 . 00 > 完全删除。我现在将编辑我的 OP。