I have a character vector containing genes and their associated colors:
gene_colors<-c("protein_coding"="#1F78B4", "lncRNA"="#de08a0")
I'm trying to go through another list of genes and add the gene with a random color if it's not already in the vector:
library(tidyverse)
library(randomcoloR)
for(gene in other_genes){
if(!(gene %in% names(gene_colors))){
temp<-paste0(gene, '=', randomColor(1))
}
}
This is what's in other_genes
:
[1] "IG_C_gene" "IG_C_pseudogene"
[3] "IG_J_gene" "IG_V_gene"
[5] "IG_V_pseudogene" "lncRNA"
[7] "miRNA" "misc_RNA"
[9] "Mt_rRNA" "polymorphic_pseudogene"
[11] "processed_pseudogene" "protein_coding"
As you can see, I tried to use paste0()
and I previously tried to use str_c()
but both of these give me a string like this "IG_C_gene=#ffd4bf"
. I want to use the gene_colors
vector in a heatmap function so I need the equals sign to be separate (ie not inside the quotes like it would be if it were a character in a string) like the entries in gene_colors
. Is there any way to do this?