qplot and geom_hline

44 views
Skip to first unread message

Guia Guffanti

unread,
Mar 7, 2009, 2:30:26 AM3/7/09
to ggp...@googlegroups.com
Hi,

I am trying to create a Manhattan plot using the qplot function.
I am plotting 500K points (the p-values of a genomic study).
I am not aware of any ggplot function specifically dedicated to this
kind of analysis, so this is the code that I was trying to use.
The result is absolutely good -- thanks to ggplot!.

genetics = qplot(Position,logpvalue, colour = factor
(Chromosomes),data = gwas, shape = snptype, xlab = "Chromosomes",
ylab = "-log10(Observed p-value)") + opts (legend.position = "none")
+ scale_x_continuous(breaks = c
(40108,82834,118522,150265,182666,218456,247383,276598,301702,329213,354
963,380422,400153,417428,433047,448851,462680,478287,487628,500917,50868
8,516645),labels = c
(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22)) +
geom_hline(yintercept=seq(3, 6, by=1))

The only two things that I am still not able to do are the following:

1) I need to include 3 cutoffs lines, corresponding to specific
values of the y axis variable (the -log 10 of the pvalues). I tried
to use geom_hline but it does not work (geom_hline(yintercept=seq(3,
6, by=1))).
I am sure I am missing something somewhere but I cannot find where.

2) I tried to save the plot to import it in Photoshop (to actually
add the cutoff lines) but I was not able to get it done.
I used the following command:

ggsave (genetics, file = "genetics.tiff", width = 480, height = 480)

assuming that the resolution is 300 dpi (which is also the resolution
requested by the journal where this plot might be submitted).
Am I using it correctly?

The plot is quite heavy (pdf format = 768 KB) so I was not sure if
the attachment was a good idea, but if you think so and it makes
easier to understand the problem I am more than happy to share it
with you.

Any help would be highly appreciated.
Thank you in advance,

Guia


hadley wickham

unread,
Mar 7, 2009, 9:36:21 AM3/7/09
to Guia Guffanti, ggp...@googlegroups.com
> I am trying to create a Manhattan plot using the qplot function.
> I am plotting 500K points (the p-values of a genomic study).
> I am not aware of any ggplot function specifically dedicated to this
> kind of analysis, so this is the code that I was trying to use.
> The result is absolutely good -- thanks to ggplot!.

Great :)

> genetics = qplot(Position,logpvalue, colour = factor
> (Chromosomes),data = gwas, shape = snptype, xlab = "Chromosomes",
> ylab = "-log10(Observed p-value)") + opts (legend.position = "none")
> + scale_x_continuous(breaks = c
> (40108,82834,118522,150265,182666,218456,247383,276598,301702,329213,354
> 963,380422,400153,417428,433047,448851,462680,478287,487628,500917,50868
> 8,516645),labels = c
> (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22)) +
> geom_hline(yintercept=seq(3, 6, by=1))
>
> The only two things that I am still not able to do are the following:
>
> 1) I need to include 3 cutoffs lines, corresponding to specific
> values of the y axis variable (the -log 10 of the pvalues). I tried
> to use geom_hline but it does not work (geom_hline(yintercept=seq(3,
> 6, by=1))).
> I am sure I am missing something somewhere but I cannot find where.

Well looking at the range of your breaks (40108 to 516645), it seems
unlikely you'd want lines drawn at 3, 4, 5 and 6.

> 2) I tried to save the plot to import it in Photoshop (to actually
> add the cutoff lines) but I was not able to get it done.
> I used the following command:
>
> ggsave (genetics, file  = "genetics.tiff", width = 480, height = 480)
>
> assuming that the resolution is 300 dpi (which is also the resolution
> requested by the journal where this plot might be submitted).
> Am I using it correctly?

Width and height are measured in inches!

Hadley

--
http://had.co.nz/

Guia Guffanti

unread,
Mar 7, 2009, 10:28:06 AM3/7/09
to hadley wickham, ggp...@googlegroups.com
Thanks for your prompt answer.
The only thing that it is still not clear is that my breaks are on
the x scale, while the lines 3,4,5 and 6 should be horizontal, in
other words referred to the y scale. Using "yintercept" I can draw an
horizontal line, but whatever I add as parameters, the line does not
move from the "0" (more likely it is 3,4,5 and 6).
Should I use somethng different than geom_hline to get horizontal lines?

Thanks,
Guia

Mike Lawrence

unread,
Mar 8, 2009, 10:47:25 AM3/8/09
to Guia Guffanti, hadley wickham, ggp...@googlegroups.com
a=as.data.frame(cbind(x=1:10,y=c(1:5,5:1)))
b=5.5
c=2.5

#this reproduces your problem:
p=qplot(data=a,x=x,y=y)
p=p+geom_vline(aes(xintercept=b))
p=p+geom_hline(aes(yintercept=c))
print(p)

#this fixes it:
p=qplot(data=a,x=x,y=y)
p=p+geom_vline(xintercept=b)
p=p+geom_hline(yintercept=c)
print(p)
--
Mike Lawrence
Graduate Student
Department of Psychology
Dalhousie University

Looking to arrange a meeting? Check my public calendar:
http://tinyurl.com/mikes-public-calendar

~ Certainty is folly... I think. ~
Reply all
Reply to author
Forward
0 new messages