Reputation: 11
I needed help knowing how to associate colors with values. For example, I have a vector for colors and values as follows i.e.
cols <- c("red", "gray60")
and
numEra <- c(values)
numEra
[1] 1 1 1 2 2 2
How do I associate these values with the colors "red" and "gray60" ??
Upvotes: 0
Views: 250
Reputation: 41285
Maybe you want to use cut
like this:
cols <- c("red", "gray60")
numEra <- c(1, 1, 1, 2, 2, 2)
cols[cut(numEra, 2)]
#> [1] "red" "red" "red" "gray60" "gray60" "gray60"
Created on 2022-10-01 with reprex v2.0.2
So each number is now associated with a color.
Upvotes: 1