How to stack two Stack manhattan plots?

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

How to stack two Stack manhattan plots?

anikaM
Hello,

I have a data frame like this:

> head(tmp1)
  CHR      BP   Pold    Pnew
1   1  785989 0.9521 0.09278
2   1 1130727 0.4750 0.19010
3   1 1156131 0.5289 0.48520
4   1 1158631 0.2554 0.18140
5   1 1211292 0.2954 0.48590
6   1 1478153 0.5542 0.68790
...

I did:
tmp.tidy <- tmp1 %>% gather(key, value, -BP, -CHR)
jpeg("over.jpeg")
ggplot(tmp.tidy, aes(BP, value, color=key)) + geom_point() +
facet_wrap(~CHR, nrow=1)
dev.off()

but I got this plot in attach which doesn't make sense. Can you please
advise how to make this plot?

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.

Screen Shot 2020-06-10 at 3.34.47 PM.png (415K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: How to stack two Stack manhattan plots?

Jeff Newmiller
?dput

We cannot tell how the columns are being stored in memory from your head() output.

On June 10, 2020 1:36:11 PM PDT, Ana Marija <[hidden email]> wrote:

>Hello,
>
>I have a data frame like this:
>
>> head(tmp1)
>  CHR      BP   Pold    Pnew
>1   1  785989 0.9521 0.09278
>2   1 1130727 0.4750 0.19010
>3   1 1156131 0.5289 0.48520
>4   1 1158631 0.2554 0.18140
>5   1 1211292 0.2954 0.48590
>6   1 1478153 0.5542 0.68790
>...
>
>I did:
>tmp.tidy <- tmp1 %>% gather(key, value, -BP, -CHR)
>jpeg("over.jpeg")
>ggplot(tmp.tidy, aes(BP, value, color=key)) + geom_point() +
>facet_wrap(~CHR, nrow=1)
>dev.off()
>
>but I got this plot in attach which doesn't make sense. Can you please
>advise how to make this plot?
>
>thanks
>Ana

--
Sent from my phone. Please excuse my brevity.

______________________________________________
[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: How to stack two Stack manhattan plots?

Jim Lemon-4
In reply to this post by anikaM
Hi Ana,
The problem may be that the JPEG device doesn't handle transparency.
Perhaps PNG?

Jim

On Thu, Jun 11, 2020 at 6:48 AM Ana Marija <[hidden email]> wrote:

>
> Hello,
>
> I have a data frame like this:
>
> > head(tmp1)
>   CHR      BP   Pold    Pnew
> 1   1  785989 0.9521 0.09278
> 2   1 1130727 0.4750 0.19010
> 3   1 1156131 0.5289 0.48520
> 4   1 1158631 0.2554 0.18140
> 5   1 1211292 0.2954 0.48590
> 6   1 1478153 0.5542 0.68790
> ...
>
> I did:
> tmp.tidy <- tmp1 %>% gather(key, value, -BP, -CHR)
> jpeg("over.jpeg")
> ggplot(tmp.tidy, aes(BP, value, color=key)) + geom_point() +
> facet_wrap(~CHR, nrow=1)
> dev.off()
>
> but I got this plot in attach which doesn't make sense. Can you please
> advise how to make this plot?
>
> 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: How to stack two Stack manhattan plots?

anikaM
HI Jim

I run it like this:
Rscript --no-save Manhattan_plot.R

and just in case I added: stringsAsFactors=FALSE

so the script looks like this:
library(qqman)
results_log <- read.table("logistic_results_M3.assoc.logistic.C",
head=TRUE,stringsAsFactors=FALSE)
jpeg("M3.assoc.logistic.jpeg")
manhattan(results_log,chr="CHR",bp="BP",p="P",snp="SNP", main =
"Manhattan plot:logistic")
dev.off()

this code does work with another data set, the jpeg() does work. I
will try now with PNG

On Wed, Jun 10, 2020 at 5:17 PM Jim Lemon <[hidden email]> wrote:

>
> Hi Ana,
> The problem may be that the JPEG device doesn't handle transparency.
> Perhaps PNG?
>
> Jim
>
> On Thu, Jun 11, 2020 at 6:48 AM Ana Marija <[hidden email]> wrote:
> >
> > Hello,
> >
> > I have a data frame like this:
> >
> > > head(tmp1)
> >   CHR      BP   Pold    Pnew
> > 1   1  785989 0.9521 0.09278
> > 2   1 1130727 0.4750 0.19010
> > 3   1 1156131 0.5289 0.48520
> > 4   1 1158631 0.2554 0.18140
> > 5   1 1211292 0.2954 0.48590
> > 6   1 1478153 0.5542 0.68790
> > ...
> >
> > I did:
> > tmp.tidy <- tmp1 %>% gather(key, value, -BP, -CHR)
> > jpeg("over.jpeg")
> > ggplot(tmp.tidy, aes(BP, value, color=key)) + geom_point() +
> > facet_wrap(~CHR, nrow=1)
> > dev.off()
> >
> > but I got this plot in attach which doesn't make sense. Can you please
> > advise how to make this plot?
> >
> > 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: How to stack two Stack manhattan plots?

cpolwart-2
What did you expect?

I'm assuming two plots (based on the subject) and side by side based on
the code (nrow =1)

But you are getting several graphs (facets) on the row and only expected
2?

What is in CHR?  i.e. summary(tmp1$CHR)

I'm assuming its not a factor with 2 elements...?


>> > Hello,
>> >
>> > I have a data frame like this:
>> >
>> > > head(tmp1)
>> >   CHR      BP   Pold    Pnew
>> > 1   1  785989 0.9521 0.09278
>> > 2   1 1130727 0.4750 0.19010
>> > 3   1 1156131 0.5289 0.48520
>> > 4   1 1158631 0.2554 0.18140
>> > 5   1 1211292 0.2954 0.48590
>> > 6   1 1478153 0.5542 0.68790
>> > ...
>> > ggplot(tmp.tidy, aes(BP, value, color=key)) + geom_point() +
>> > facet_wrap(~CHR, nrow=1)

______________________________________________
[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: How to stack two Stack manhattan plots?

R help mailing list-2
In reply to this post by anikaM
On Wed, 10 Jun 2020 15:36:11 -0500
Ana Marija <[hidden email]> wrote:

> Hello,
>
> I have a data frame like this:
>
> > head(tmp1)  
>   CHR      BP   Pold    Pnew
> 1   1  785989 0.9521 0.09278
> 2   1 1130727 0.4750 0.19010
> 3   1 1156131 0.5289 0.48520
> 4   1 1158631 0.2554 0.18140
> 5   1 1211292 0.2954 0.48590
> 6   1 1478153 0.5542 0.68790
> ...
>
> I did:
> tmp.tidy <- tmp1 %>% gather(key, value, -BP, -CHR)
> jpeg("over.jpeg")
> ggplot(tmp.tidy, aes(BP, value, color=key)) + geom_point() +
> facet_wrap(~CHR, nrow=1)
> dev.off()
>
> but I got this plot in attach which doesn't make sense. Can you please
> advise how to make this plot?
>
> thanks
> Ana

If you would, the str() output might help people understand what is
happening, and also how many records you're looking at.  The head()
output is a bit thin on information.  There are various manhattan plot
packages for R including a specialized package for ggplot2.

JWDougherty

______________________________________________
[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: How to stack two Stack manhattan plots?

anikaM
Hello,

I expected it to look like this:
https://imgur.com/a/pj40c

where x-axis would be CHR, there is 22 of them
> unique(tmp.tidy$CHR)
 [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22

I also have two phenotypes (keys) which I would like to compare
> unique(tmp.tidy$key)
[1] "Pold" "Pnew"

> dim(tmp.tidy)
[1] 2600184       4

I would like the x-axis to be separated by CHR

> sapply(tmp.tidy,class)
        CHR          BP         key       value
  "integer"   "integer" "character"   "numeric"

> str(tmp.tidy)
'data.frame':    2600184 obs. of  4 variables:
 $ CHR  : int  1 1 1 1 1 1 1 1 1 1 ...
 $ BP   : int  785989 1130727 1156131 1158631 1211292 1478153 1500941
1506035 1510801 1721479 ...
 $ key  : chr  "Pold" "Pold" "Pold" "Pold" ...
 $ value: num  0.952 0.475 0.529 0.255 0.295 ...

Unfortunately qqman doesn't do this kind of overlay of two plots

On Wed, Jun 10, 2020 at 11:24 PM John <[hidden email]> wrote:

>
> On Wed, 10 Jun 2020 15:36:11 -0500
> Ana Marija <[hidden email]> wrote:
>
> > Hello,
> >
> > I have a data frame like this:
> >
> > > head(tmp1)
> >   CHR      BP   Pold    Pnew
> > 1   1  785989 0.9521 0.09278
> > 2   1 1130727 0.4750 0.19010
> > 3   1 1156131 0.5289 0.48520
> > 4   1 1158631 0.2554 0.18140
> > 5   1 1211292 0.2954 0.48590
> > 6   1 1478153 0.5542 0.68790
> > ...
> >
> > I did:
> > tmp.tidy <- tmp1 %>% gather(key, value, -BP, -CHR)
> > jpeg("over.jpeg")
> > ggplot(tmp.tidy, aes(BP, value, color=key)) + geom_point() +
> > facet_wrap(~CHR, nrow=1)
> > dev.off()
> >
> > but I got this plot in attach which doesn't make sense. Can you please
> > advise how to make this plot?
> >
> > thanks
> > Ana
>
> If you would, the str() output might help people understand what is
> happening, and also how many records you're looking at.  The head()
> output is a bit thin on information.  There are various manhattan plot
> packages for R including a specialized package for ggplot2.
>
> JWDougherty

______________________________________________
[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: How to stack two Stack manhattan plots?

cpolwart-2
On 2020-06-11 14:54, Ana Marija wrote:
> Hello,
>
> I expected it to look like this:
> https://imgur.com/a/pj40c
>

Ah - so all on the one plot? - so you don't want a facet. It puts two
plots side by side (or 22)

> where x-axis would be CHR, there is 22 of them
>> unique(tmp.tidy$CHR)
>  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22
>

You have 22 plots all appearing side by size as part of the facet

I think you want color=CHR - but I don't know what your current color
setting is doing.

> I also have two phenotypes (keys) which I would like to compare
>> unique(tmp.tidy$key)
> [1] "Pold" "Pnew"
>

So did you want to Facet those?

______________________________________________
[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: How to stack two Stack manhattan plots?

anikaM
yes all in one plot.
So I want key (and therefore color)to be "Pold" and "Pnew" as those I
am comparing per CHR
so I used facet_wrap(~CHR) to create a graph per chromosome (on x-axis)
On the end x-axis would have two strikes of Pold and Pnew (different
colors) per one chromosome, and CHR would go from 1 to 22

On Thu, Jun 11, 2020 at 9:26 AM <[hidden email]> wrote:

>
> On 2020-06-11 14:54, Ana Marija wrote:
> > Hello,
> >
> > I expected it to look like this:
> > https://imgur.com/a/pj40c
> >
>
> Ah - so all on the one plot? - so you don't want a facet. It puts two
> plots side by side (or 22)
>
> > where x-axis would be CHR, there is 22 of them
> >> unique(tmp.tidy$CHR)
> >  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22
> >
>
> You have 22 plots all appearing side by size as part of the facet
>
> I think you want color=CHR - but I don't know what your current color
> setting is doing.
>
> > I also have two phenotypes (keys) which I would like to compare
> >> unique(tmp.tidy$key)
> > [1] "Pold" "Pnew"
> >
>
> So did you want to Facet those?

______________________________________________
[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: How to stack two Stack manhattan plots?

cpolwart-2
On 2020-06-11 15:59, Ana Marija wrote:
> yes all in one plot.
> So I want key (and therefore color)to be "Pold" and "Pnew" as those I
> am comparing per CHR
> so I used facet_wrap(~CHR) to create a graph per chromosome (on x-axis)
> On the end x-axis would have two strikes of Pold and Pnew (different
> colors) per one chromosome, and CHR would go from 1 to 22
>


ggplot( data = tmp.tidy) +
geom_point( aes(
             y = BP,
             x = CHR,
             color=key) )

?

______________________________________________
[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: How to stack two Stack manhattan plots?

anikaM
Hello,

I tried your code and this is what I got

I really need two groups side by side shown per chromosome as it is here:
https://imgur.com/a/pj40c
on the image there are 4 groups I do have only two

On Thu, Jun 11, 2020 at 11:52 AM <[hidden email]> wrote:

>
> On 2020-06-11 15:59, Ana Marija wrote:
> > yes all in one plot.
> > So I want key (and therefore color)to be "Pold" and "Pnew" as those I
> > am comparing per CHR
> > so I used facet_wrap(~CHR) to create a graph per chromosome (on x-axis)
> > On the end x-axis would have two strikes of Pold and Pnew (different
> > colors) per one chromosome, and CHR would go from 1 to 22
> >
>
>
> ggplot( data = tmp.tidy) +
> geom_point( aes(
>              y = BP,
>              x = CHR,
>              color=key) )
>
> ?
______________________________________________
[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: How to stack two Stack manhattan plots?

anikaM
I tried it,
ggplot( data = tmp.tidy) +geom_point( aes(y = BP,x = CHR,color=key)
,position = "jitter" )
I got the attached

On Thu, Jun 11, 2020 at 4:18 PM <[hidden email]> wrote:

>
> Try adding
> position = "jitter" to the geom_point(...
>
>
>
> On 11 Jun 2020 21:41, Ana Marija <[hidden email]> wrote:
>
> Hello,
>
> I tried your code and this is what I got
>
> I really need two groups side by side shown per chromosome as it is here:
> https://imgur.com/a/pj40c
> on the image there are 4 groups I do have only two
>
> On Thu, Jun 11, 2020 at 11:52 AM <[hidden email]> wrote:
> >
> > On 2020-06-11 15:59, Ana Marija wrote:
> > > yes all in one plot.
> > > So I want key (and therefore color)to be "Pold" and "Pnew" as those I
> > > am comparing per CHR
> > > so I used facet_wrap(~CHR) to create a graph per chromosome (on x-axis)
> > > On the end x-axis would have two strikes of Pold and Pnew (different
> > > colors) per one chromosome, and CHR would go from 1 to 22
> > >
> >
> >
> > ggplot( data = tmp.tidy) +
> > geom_point( aes(
> >              y = BP,
> >              x = CHR,
> >              color=key) )
> >
> > ?
>
>
______________________________________________
[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: How to stack two Stack manhattan plots?

anikaM
Thank you so much it is getting better (see attach) when I do:
ggplot( data = tmp.tidy) +geom_point( aes(y = -log10(value),x =
CHR,color=key) ,position = "jitter", size=0.5 )

is there is a way to have separation between every chromosome shown
better and also every number of chromosome shown on the x-axis?

On Thu, Jun 11, 2020 at 4:39 PM <[hidden email]> wrote:

>
> Your dots are too big!
>
> Add
>
> geom_points(... , size = 1
>
> May need to play... 0.5 or 0.1?
>
> On 11 Jun 2020 22:26, Ana Marija <[hidden email]> wrote:
>
> I tried it,
> ggplot( data = tmp.tidy) +geom_point( aes(y = BP,x = CHR,color=key)
> ,position = "jitter" )
> I got the attached
>
> On Thu, Jun 11, 2020 at 4:18 PM <[hidden email]> wrote:
> >
> > Try adding
> > position = "jitter" to the geom_point(...
> >
> >
> >
> > On 11 Jun 2020 21:41, Ana Marija <[hidden email]> wrote:
> >
> > Hello,
> >
> > I tried your code and this is what I got
> >
> > I really need two groups side by side shown per chromosome as it is here:
> > https://imgur.com/a/pj40c
> > on the image there are 4 groups I do have only two
> >
> > On Thu, Jun 11, 2020 at 11:52 AM <[hidden email]> wrote:
> > >
> > > On 2020-06-11 15:59, Ana Marija wrote:
> > > > yes all in one plot.
> > > > So I want key (and therefore color)to be "Pold" and "Pnew" as those I
> > > > am comparing per CHR
> > > > so I used facet_wrap(~CHR) to create a graph per chromosome (on x-axis)
> > > > On the end x-axis would have two strikes of Pold and Pnew (different
> > > > colors) per one chromosome, and CHR would go from 1 to 22
> > > >
> > >
> > >
> > > ggplot( data = tmp.tidy) +
> > > geom_point( aes(
> > >              y = BP,
> > >              x = CHR,
> > >              color=key) )
> > >
> > > ?
> >
> >
>
>
______________________________________________
[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.