Issues with col2rgb
1
0
Entering edit mode
4.8 years ago
anamaria ▴ 220

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 • 853 views
ADD COMMENT
0
Entering edit mode

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.

ADD REPLY
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode
4.8 years ago
anamaria ▴ 220

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

 dim1 in 1:2
ADD COMMENT

Login before adding your answer.

Traffic: 2009 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6