The
The information needed can be found on the WCS page,
Clearly, the chips are not ordered along hue and value but with reference to some other dimension, perhaps even order in the original data frame. I also have to revert the order on the y-axis. I guess the solution will have to do with factor()
and reorder()
, but how to do it?
CodePudding user response:
The main thing is to use the right color scale (scale_fill_identity
). This ensures the hex values are uses as the color for the tiles.
library(munsell)
library(ggplot2)
WCS <- read.csv(url('https://www1.icsi.berkeley.edu/wcs/data/cnum-maps/cnum-vhcm-lab-new.txt'), sep = "\t", header = T)
WCS$hex <- mnsl2hex(hvc2mnsl(hue = gsub('.00','',gsub('.50', '.5',WCS$MunH)), value = ceiling(WCS$MunV), chroma = WCS$C), fix = T)
ggplot(aes(x=H, y=V, fill=hex), data = WCS)
geom_tile(aes(x=H, y=V), show.legend = F)
scale_fill_identity()
scale_x_continuous(breaks = scales::pretty_breaks(n = 40))
Created on 2021-10-05 by the
You have show.legend = F
in there, but there should be 324 different values mapped to the WCS$hex
column (i.e. length(unique(WCS$hex))
).
When using scale_fill_manual(values=...)
, you are supplying the names of the colors to be used, but they are not mapped to the same positions in your column WCS$hex
. They are applied according to the way in which ggplot2
decides to organize the levels of WCS$hex
as if it were a factor.
In order to tell ggplot2
to basically ignore the mapping and just color according to the actual color name you see in the column mapped to fill
, you use scale_fill_identity()
. This will necessarily remove the ability to show any legend, since it kind of removes the mapping and recoloring that is the default behavior of aes(fill=...)
. Regardless, this should solve your issue:
ggplot(aes(x=H, y=V, fill=hex), data = WCS)
geom_tile(aes(x=H, y=V), width=0.8, height=0.8)
scale_fill_identity()
scale_y_discrete(limits = rev(levels(WCS$V)))
scale_x_continuous(breaks = scales::pretty_breaks(n = 40))
coord_fixed()
theme(
panel.grid = element_blank()
)