scatter plot

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

scatter plot

anikaM
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

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: scatter plot

John Kane-3
I must admit that I do not understand what you are doing but can you notm
just subset the data?
Note I am using a data.frame not a tibble.  It would be helpful if you
could supply sample data in dput() forest.

library("ggpubr")
mds  <-  structure(list(Dim.1 = c(0.41, 0.184, 0.394, -0.49, 0.635, -0.723,
0.76, -0.0918, -0.336, -0.439, -1.9, 0.631), Dim.2 = c(-0.984,
1.11, -0.159, -0.326, -0.112, 0.153, -0.732, 0.645, 0.756, -0.557,
-0.858, -0.093), Dim.3 = c(-0.87, 0.101, 0.0272, 0.535, -0.0503,
-0.245, 0.568, -0.189, 0.12, 0.556, -0.949, 1.43), cols = c("nPDR.rg",
"nPDR.rg", "nPDR.rg", "nPDR.rg", "nPDR.rg", "nPDR.rg", "NoD.rg",
"NoD.rg", "NoD.rg", "NoD.rg", "NoD.rg", "NoD.rg")), class = "data.frame",
row.names = c(NA,
-12L))

mm1  <-  subset(mds, cols =="nPDR.rg")
ggscatter(mds, x = d1, y = d2, size=3, color = "red")

On Mon, 10 Feb 2020 at 14:04, Ana Marija <[hidden email]>
wrote:

> 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
>
> ______________________________________________
> [hidden email] 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.
>


--
John Kane
Kingston ON Canada

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: scatter plot

anikaM
Hi,

Thanks for getting back to me. I need to have there two groups:

"nPDR.rg  and "PDR.rg"

can you please let me know how my loop would look like just with those
two groups?

Thanks
Ana

On Mon, Feb 10, 2020 at 2:03 PM John Kane <[hidden email]> wrote:

>
> I must admit that I do not understand what you are doing but can you notm just subset the data?
> Note I am using a data.frame not a tibble.  It would be helpful if you could supply sample data in dput() forest.
>
> library("ggpubr")
> mds  <-  structure(list(Dim.1 = c(0.41, 0.184, 0.394, -0.49, 0.635, -0.723,
> 0.76, -0.0918, -0.336, -0.439, -1.9, 0.631), Dim.2 = c(-0.984,
> 1.11, -0.159, -0.326, -0.112, 0.153, -0.732, 0.645, 0.756, -0.557,
> -0.858, -0.093), Dim.3 = c(-0.87, 0.101, 0.0272, 0.535, -0.0503,
> -0.245, 0.568, -0.189, 0.12, 0.556, -0.949, 1.43), cols = c("nPDR.rg",
> "nPDR.rg", "nPDR.rg", "nPDR.rg", "nPDR.rg", "nPDR.rg", "NoD.rg",
> "NoD.rg", "NoD.rg", "NoD.rg", "NoD.rg", "NoD.rg")), class = "data.frame", row.names = c(NA,
> -12L))
>
> mm1  <-  subset(mds, cols =="nPDR.rg")
> ggscatter(mds, x = d1, y = d2, size=3, color = "red")
>
> On Mon, 10 Feb 2020 at 14:04, Ana Marija <[hidden email]> wrote:
>>
>> 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
>>
>> ______________________________________________
>> [hidden email] 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.
>
>
>
> --
> John Kane
> Kingston ON Canada

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: scatter plot

Rui Barradas
In reply to this post by anikaM
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
>
> ______________________________________________
> [hidden email] 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.
>

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: scatter plot

John Kane-3
In reply to this post by anikaM
In line

On Mon, 10 Feb 2020 at 15:12, Ana Marija <[hidden email]>
wrote:

> Hi,
>
> Thanks for getting back to me. I need to have there two groups:
>
> "nPDR.rg  and "PDR.rg"
>

Your sample data only contains NoD.rg &  nPDR.rg.  To start with, I think
we need some representative data supplied in dput format just as I supplied
an "mds" dataset.  If I understand your mds$col statement correctly there
is only 22 rows of data. Just issue the command "dput(mds) and copy the
output into your e-mail. This will allow R-help readers to use the exact
same data set that you have on your computer.

>
> can you please let me know how my loop would look like just with those
> two groups
>

Well no I cannot  because I am still trying ta figure out where "d1 and d2
came from or why you need that loop. It looks like you are renaming the
columns in "mbs" three times but why? And why do it in a loop?

If all that you are doing is renaming the columns from the "ar_diff" data
set names just do it once,
colnames(mds)  <-  c("Dim.1", Dim.2, Dim.3) before you even create the
"cols" column.

We really need to see the data.

I have never used library("ggpubr") and I cannot see why cols is appearing
in the legend---well it does with my data set. Actually, given my version
of the data set I don't see why it it printing the graph.


Also do you really want all three grcaphs in one .pdf file?



> Thanks
> Ana
>
>










> On Mon, Feb 10, 2020 at 2:03 PM John Kane <[hidden email]> wrote:
> >
> > I must admit that I do not understand what you are doing but can you
> notm just subset the data?
> > Note I am using a data.frame not a tibble.  It would be helpful if you
> could supply sample data in dput() forest.
> >
> > library("ggpubr")
> > mds  <-  structure(list(Dim.1 = c(0.41, 0.184, 0.394, -0.49, 0.635,
> -0.723,
> > 0.76, -0.0918, -0.336, -0.439, -1.9, 0.631), Dim.2 = c(-0.984,
> > 1.11, -0.159, -0.326, -0.112, 0.153, -0.732, 0.645, 0.756, -0.557,
> > -0.858, -0.093), Dim.3 = c(-0.87, 0.101, 0.0272, 0.535, -0.0503,
> > -0.245, 0.568, -0.189, 0.12, 0.556, -0.949, 1.43), cols = c("nPDR.rg",
> > "nPDR.rg", "nPDR.rg", "nPDR.rg", "nPDR.rg", "nPDR.rg", "NoD.rg",
> > "NoD.rg", "NoD.rg", "NoD.rg", "NoD.rg", "NoD.rg")), class =
> "data.frame", row.names = c(NA,
> > -12L))
> >
> > mm1  <-  subset(mds, cols =="nPDR.rg")
> > ggscatter(mds, x = d1, y = d2, size=3, color = "red")
> >
> > On Mon, 10 Feb 2020 at 14:04, Ana Marija <[hidden email]>
> wrote:
> >>
> >> 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
> >>
> >> ______________________________________________
> >> [hidden email] 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.
> >
> >
> >
> > --
> > John Kane
> > Kingston ON Canada
>


--
John Kane
Kingston ON Canada

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.