This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Issues with col2rgb

Hi,

this is my data and code:

> rownames(cc)
 [1] "DwoC_2318_30mM"  "DwoC_3395_30mM"  "DwoC_6154_30mM"  "DwoC_16362_30mM"
 [5] "DwoC_18296_30mM" "DwoC_21183_30mM" "DwoC_25224_30mM" "DwC_1026_30mM"  
 [9] "DwC_6009_30mM"   "DwC_11167_30mM"  "DwC_13206_30mM"  "DwC_17075_30mM" 
[13] "DwC_21127_30mM"  "DwC_26008_30mM"  "DwC_27141_30mM"  "NoD_7012_30mM"  
[17] "NoD_7344_30mM"   "NoD_11985_30mM"  "NoD_14381_30mM"  "NoD_14520_30mM" 
[21] "NoD_14569_30mM"  "NoD_14581_30mM" 
> mds <- cc %>% dist() %>% cmdscale(k=3)
> mds <- cc %>% dist() %>% cmdscale(k=3) %>% as_tibble()
> mds$cols <- as.factor(c(rep("nPDR.hg",8),  rep("PDR.hg",7),  rep("NoD.hg",7))) 
> pdf(file = "MDS_gene_expression_new_reduced_HG.pdf")
> 
> 
>                     for (dim1 in 1:3){
+                     for (dim2 in (dim1+1):3){
+                         d1 = paste0("Dim.",dim1); d2 = paste0("Dim.",dim2)
+                         colnames(mds)[c(dim1,dim2)] <- c(d1,d2)
+                         print(ggscatter(mds, x = d1, y = d2, color = "cols",size=3 ,palette=c("blue","red","yellow")))
+                     }
 +                 }
  Error in grDevices::col2rgb(colour, TRUE) : invalid color name 'cols'
> dev.off()

Does anyone know why I am getting this Error?

> head(mds)
# A tibble: 6 x 4
       V1    V2     V3 cols   
    <dbl> <dbl>  <dbl> <fct>  
1   2.97  -5.92  2.56  nPDR.hg
2  -0.323 -4.95  1.77  nPDR.hg
3 -11.8   -5.20 -3.83  nPDR.hg
4  -1.85   3.87 -0.271 nPDR.hg
5   2.34  -6.91  2.42  nPDR.hg
6  -4.81  -6.85  0.952 nPDR.hg

Thanks Ana

r

Try removing the quotes around cols. In ggplot2, this is meant to refer to the cols column of the data frame containing the data. By the way this is a question for StackOverflow since it's about R programming.

HI, I tried color = cols but again the same error.

1 answer

it was wrong dimension in the loop, it should be:

 dim1 in 1:2

Log in to answer this question.