[R] scatter plot

Rui Barradas ru|pb@rr@d@@ @end|ng |rom @@po@pt
Mon Feb 10 23:54:45 CET 2020


Hello,

In the loop, try filtering out the values you do not want.

Any of

print(ggscatter(mds %>% dplyr::filter(cols != "NoD.rg"), etc))

print(ggscatter(subset(mds, cols != "NoD.rg"), etc))

tmp <- mds %>% filter(cols != "NoD.rg")
print(ggscatter(tmp, etc))


The first two will create a temporary df, the 3rd a permanent one. 
Remove it after the loop:

rm(tmp)


Hope this helps,

Rui Barradas


Às 19:09 de 10/02/20, Ana Marija escreveu:
> 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
> 
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list