[R] scatter plot

Ana Marija @okov|c@@n@m@r|j@ @end|ng |rom gm@||@com
Mon Feb 10 20:09:32 CET 2020


Hello,

I have a code like this:

mds <- (ar_diff) %>% dist() %>% cmdscale(k=3) %>% as_tibble()
mds$cols <- as.factor(c(rep("nPDR.rg",7),  rep("PDR.rg",8),  rep("NoD.rg",7)))

pdf(file = "RG.pdf")


for (dim1 in 1:2){
  for (dim2 in (dim1+1):3){
    d1 = paste0("Dim.",dim1); d2 = paste0("Dim.",dim2)
    colnames(mds)[c(dim1,dim2)] <- c(d1,d2)
    print(colnames(mds))
    print(ggscatter(mds, x = d1, y = d2, color ="cols" ,size=3
,palette=c("blue","red","green")))
  }
}
dev.off()

How do I run the same plot but excluding NoD.rg? What do I need to
change in this for loop?

> head(mds)
# A tibble: 6 x 4
   Dim.1  Dim.2   Dim.3 cols
   <dbl>  <dbl>   <dbl> <fct>
1  1.41  -0.984 -0.870  nPDR.rg
2  0.184  1.11   0.101  nPDR.rg
3  0.394 -0.159  0.0272 nPDR.rg
4 -0.490 -0.326  0.535  nPDR.rg
5  0.635 -0.112 -0.0503 nPDR.rg
6 -0.723  0.153 -0.245  nPDR.rg

> tail(mds)
# A tibble: 6 x 4
    Dim.1   Dim.2  Dim.3 cols
    <dbl>   <dbl>  <dbl> <fct>
1  0.760  -0.732   0.568 NoD.rg
2 -0.0918  0.645  -0.189 NoD.rg
3 -0.336   0.756   0.120 NoD.rg
4 -0.439  -0.557   0.556 NoD.rg
5 -1.90   -0.858  -0.949 NoD.rg
6  0.631  -0.0930  1.43  NoD.rg

Thanks
Ana



More information about the R-help mailing list