lets say you have a goal of arriving at the following vector, that you intend to use by passing as the values argument of scale_color_manual
goal <- c("CM1"= "dodgerblue2",
"CM2"="green4",
"CM3"="black", "CM4"="gold1",
"CM6"= "palegreen2",
"EC1"="gray70", "EC2"="khaki2",
"EC3"="maroon","ECFB"= "orchid1", "FB"="deeppink1",
"Leuko1"="blue1", "Leuko2"="steelblue4",
"NLC"= "darkturquoise", "PC"="green1", "SMC"="yellow3",
"Unk1"= "darkorange4", "Unk2"="brown")
)
and you are starting with vectors containing the information (r_celltype,r_color)
(name_vec <- c("CM1", "CM2", "CM3", "CM4", "CM6", "EC1", "EC2", "EC3", "ECFB",
"FB", "Leuko1", "Leuko2", "NLC", "PC", "SMC", "Unk1", "Unk2"))
(color_vec <- c("dodgerblue2", "green4", "black", "gold1", "palegreen2", "gray70",
"khaki2", "maroon", "orchid1", "deeppink1", "blue1", "steelblue4",
"darkturquoise", "green1", "yellow3", "darkorange4", "brown"))
You can make your goal named vector from these two vectors via the following approach
solution <-color_vec
names(solution)<- name_vec
identical(solution,goal)
the last line verifies that we produces solution and it matches our goal.