<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://genome.sph.umich.edu/w/index.php?action=history&amp;feed=atom&amp;title=Code_Sample%3A_Generating_Manhattan_Plots_in_R</id>
	<title>Code Sample: Generating Manhattan Plots in R - Revision history</title>
	<link rel="self" type="application/atom+xml" href="http://genome.sph.umich.edu/w/index.php?action=history&amp;feed=atom&amp;title=Code_Sample%3A_Generating_Manhattan_Plots_in_R"/>
	<link rel="alternate" type="text/html" href="http://genome.sph.umich.edu/w/index.php?title=Code_Sample:_Generating_Manhattan_Plots_in_R&amp;action=history"/>
	<updated>2026-09-25T01:40:40Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.1</generator>
	<entry>
		<id>http://genome.sph.umich.edu/w/index.php?title=Code_Sample:_Generating_Manhattan_Plots_in_R&amp;diff=9356&amp;oldid=prev</id>
		<title>Mflick at 14:49, 14 January 2014</title>
		<link rel="alternate" type="text/html" href="http://genome.sph.umich.edu/w/index.php?title=Code_Sample:_Generating_Manhattan_Plots_in_R&amp;diff=9356&amp;oldid=prev"/>
		<updated>2014-01-14T14:49:36Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 10:49, 14 January 2014&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l416&quot;&gt;Line 416:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 416:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;should work well.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;should work well.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;= Alternatives =&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-added&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-added&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Note that Cristen Willer and Serena Sanna have also made many beautiful plots for GWAS data using R base graphics. They have provided a sample script that does many of the same things as the above function, plus takes care of reading in the data, highlighting known SNPs, and making QQ plots. The sample code can be found at&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-added&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;    snowwhite:/home/cristen/scripts/makeplot_manhattan_qq_forsharing.R&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-added&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:Code Samples]]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:Code Samples]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Mflick</name></author>
	</entry>
	<entry>
		<id>http://genome.sph.umich.edu/w/index.php?title=Code_Sample:_Generating_Manhattan_Plots_in_R&amp;diff=6185&amp;oldid=prev</id>
		<title>Goncalo at 19:53, 9 January 2013</title>
		<link rel="alternate" type="text/html" href="http://genome.sph.umich.edu/w/index.php?title=Code_Sample:_Generating_Manhattan_Plots_in_R&amp;diff=6185&amp;oldid=prev"/>
		<updated>2013-01-09T19:53:17Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 15:53, 9 January 2013&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l2&quot;&gt;Line 2:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 2:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[File:Sample-manhattan-plot.png|center]]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[File:Sample-manhattan-plot.png|center]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;= Credit =&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;This page is based on a tutorial originally written by [mailto:mflick@umich.edu Matthew Flickinger].&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;= Manhattan Plotting Function =&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;= Manhattan Plotting Function =&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Goncalo</name></author>
	</entry>
	<entry>
		<id>http://genome.sph.umich.edu/w/index.php?title=Code_Sample:_Generating_Manhattan_Plots_in_R&amp;diff=6181&amp;oldid=prev</id>
		<title>Goncalo: Created page with &#039;A useful way to summarize genome-wide association data is with a Manhattan plot. This type of plot has a point for every SNP or location tested with the position in the genome al…&#039;</title>
		<link rel="alternate" type="text/html" href="http://genome.sph.umich.edu/w/index.php?title=Code_Sample:_Generating_Manhattan_Plots_in_R&amp;diff=6181&amp;oldid=prev"/>
		<updated>2013-01-09T19:17:55Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;#039;A useful way to summarize genome-wide association data is with a Manhattan plot. This type of plot has a point for every SNP or location tested with the position in the genome al…&amp;#039;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;A useful way to summarize genome-wide association data is with a Manhattan plot. This type of plot has a point for every SNP or location tested with the position in the genome along the x-axis and the -log10 p-value on the y-axis. &lt;br /&gt;
&lt;br /&gt;
[[File:Sample-manhattan-plot.png|center]]&lt;br /&gt;
&lt;br /&gt;
= Manhattan Plotting Function =&lt;br /&gt;
&lt;br /&gt;
Here is a function which can make a Manhattan plot using lattice graphics. While the function itself is quite long, you don&amp;#039;t have to worry about most of it. You really only need to pay attention to the parameters that you pass to the funciton. An example of its use is given below.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;rsplus&amp;quot;&amp;gt;&lt;br /&gt;
library(lattice)&lt;br /&gt;
manhattan.plot&amp;lt;-function(chr, pos, pvalue, &lt;br /&gt;
	sig.level=NA, annotate=NULL, ann.default=list(),&lt;br /&gt;
	should.thin=T, thin.pos.places=2, thin.logp.places=2, &lt;br /&gt;
	xlab=&amp;quot;Chromosome&amp;quot;, ylab=expression(-log[10](p-value)),&lt;br /&gt;
	col=c(&amp;quot;gray&amp;quot;,&amp;quot;darkgray&amp;quot;), panel.extra=NULL, pch=20, cex=0.8,...) {&lt;br /&gt;
&lt;br /&gt;
	if (length(chr)==0) stop(&amp;quot;chromosome vector is empty&amp;quot;)&lt;br /&gt;
	if (length(pos)==0) stop(&amp;quot;position vector is empty&amp;quot;)&lt;br /&gt;
	if (length(pvalue)==0) stop(&amp;quot;pvalue vector is empty&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
	#make sure we have an ordered factor&lt;br /&gt;
	if(!is.ordered(chr)) {&lt;br /&gt;
		chr &amp;lt;- ordered(chr)&lt;br /&gt;
	} else {&lt;br /&gt;
		chr &amp;lt;- chr[,drop=T]&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	#make sure positions are in kbp&lt;br /&gt;
	if (any(pos&amp;gt;1e6)) pos&amp;lt;-pos/1e6;&lt;br /&gt;
&lt;br /&gt;
	#calculate absolute genomic position&lt;br /&gt;
	#from relative chromosomal positions&lt;br /&gt;
	posmin &amp;lt;- tapply(pos,chr, min);&lt;br /&gt;
	posmax &amp;lt;- tapply(pos,chr, max);&lt;br /&gt;
	posshift &amp;lt;- head(c(0,cumsum(posmax)),-1);&lt;br /&gt;
	names(posshift) &amp;lt;- levels(chr)&lt;br /&gt;
	genpos &amp;lt;- pos + posshift[chr];&lt;br /&gt;
	getGenPos&amp;lt;-function(cchr, cpos) {&lt;br /&gt;
		p&amp;lt;-posshift[as.character(cchr)]+cpos&lt;br /&gt;
		return(p)&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	#parse annotations&lt;br /&gt;
	grp &amp;lt;- NULL&lt;br /&gt;
	ann.settings &amp;lt;- list()&lt;br /&gt;
	label.default&amp;lt;-list(x=&amp;quot;peak&amp;quot;,y=&amp;quot;peak&amp;quot;,adj=NULL, pos=3, offset=0.5, &lt;br /&gt;
		col=NULL, fontface=NULL, fontsize=NULL, show=F)&lt;br /&gt;
	parse.label&amp;lt;-function(rawval, groupname) {&lt;br /&gt;
		r&amp;lt;-list(text=groupname)&lt;br /&gt;
		if(is.logical(rawval)) {&lt;br /&gt;
			if(!rawval) {r$show &amp;lt;- F}&lt;br /&gt;
		} else if (is.character(rawval) || is.expression(rawval)) {&lt;br /&gt;
			if(nchar(rawval)&amp;gt;=1) {&lt;br /&gt;
				r$text &amp;lt;- rawval&lt;br /&gt;
			}&lt;br /&gt;
		} else if (is.list(rawval)) {&lt;br /&gt;
			r &amp;lt;- modifyList(r, rawval)&lt;br /&gt;
		}&lt;br /&gt;
		return(r)&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	if(!is.null(annotate)) {&lt;br /&gt;
		if (is.list(annotate)) {&lt;br /&gt;
			grp &amp;lt;- annotate[[1]]&lt;br /&gt;
		} else {&lt;br /&gt;
			grp &amp;lt;- annotate&lt;br /&gt;
		} &lt;br /&gt;
		if (!is.factor(grp)) {&lt;br /&gt;
			grp &amp;lt;- factor(grp)&lt;br /&gt;
		}&lt;br /&gt;
	} else {&lt;br /&gt;
		grp &amp;lt;- factor(rep(1, times=length(pvalue)))&lt;br /&gt;
	}&lt;br /&gt;
  &lt;br /&gt;
	ann.settings&amp;lt;-vector(&amp;quot;list&amp;quot;, length(levels(grp)))&lt;br /&gt;
	ann.settings[[1]]&amp;lt;-list(pch=pch, col=col, cex=cex, fill=col, label=label.default)&lt;br /&gt;
&lt;br /&gt;
	if (length(ann.settings)&amp;gt;1) { &lt;br /&gt;
		lcols&amp;lt;-trellis.par.get(&amp;quot;superpose.symbol&amp;quot;)$col &lt;br /&gt;
		lfills&amp;lt;-trellis.par.get(&amp;quot;superpose.symbol&amp;quot;)$fill&lt;br /&gt;
		for(i in 2:length(levels(grp))) {&lt;br /&gt;
			ann.settings[[i]]&amp;lt;-list(pch=pch, &lt;br /&gt;
				col=lcols[(i-2) %% length(lcols) +1 ], &lt;br /&gt;
				fill=lfills[(i-2) %% length(lfills) +1 ], &lt;br /&gt;
				cex=cex, label=label.default);&lt;br /&gt;
			ann.settings[[i]]$label$show &amp;lt;- T&lt;br /&gt;
		}&lt;br /&gt;
		names(ann.settings)&amp;lt;-levels(grp)&lt;br /&gt;
	}&lt;br /&gt;
	for(i in 1:length(ann.settings)) {&lt;br /&gt;
		if (i&amp;gt;1) {ann.settings[[i]] &amp;lt;- modifyList(ann.settings[[i]], ann.default)}&lt;br /&gt;
		ann.settings[[i]]$label &amp;lt;- modifyList(ann.settings[[i]]$label, &lt;br /&gt;
			parse.label(ann.settings[[i]]$label, levels(grp)[i]))&lt;br /&gt;
	}&lt;br /&gt;
	if(is.list(annotate) &amp;amp;&amp;amp; length(annotate)&amp;gt;1) {&lt;br /&gt;
		user.cols &amp;lt;- 2:length(annotate)&lt;br /&gt;
		ann.cols &amp;lt;- c()&lt;br /&gt;
		if(!is.null(names(annotate[-1])) &amp;amp;&amp;amp; all(names(annotate[-1])!=&amp;quot;&amp;quot;)) {&lt;br /&gt;
			ann.cols&amp;lt;-match(names(annotate)[-1], names(ann.settings))&lt;br /&gt;
		} else {&lt;br /&gt;
			ann.cols&amp;lt;-user.cols-1&lt;br /&gt;
		}&lt;br /&gt;
		for(i in seq_along(user.cols)) {&lt;br /&gt;
			if(!is.null(annotate[[user.cols[i]]]$label)) {&lt;br /&gt;
				annotate[[user.cols[i]]]$label&amp;lt;-parse.label(annotate[[user.cols[i]]]$label, &lt;br /&gt;
					levels(grp)[ann.cols[i]])&lt;br /&gt;
			}&lt;br /&gt;
			ann.settings[[ann.cols[i]]]&amp;lt;-modifyList(ann.settings[[ann.cols[i]]], &lt;br /&gt;
				annotate[[user.cols[i]]])&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
 	rm(annotate)&lt;br /&gt;
&lt;br /&gt;
	#reduce number of points plotted&lt;br /&gt;
	if(should.thin) {&lt;br /&gt;
		thinned &amp;lt;- unique(data.frame(&lt;br /&gt;
			logp=round(-log10(pvalue),thin.logp.places), &lt;br /&gt;
			pos=round(genpos,thin.pos.places), &lt;br /&gt;
			chr=chr,&lt;br /&gt;
			grp=grp)&lt;br /&gt;
		)&lt;br /&gt;
		logp &amp;lt;- thinned$logp&lt;br /&gt;
		genpos &amp;lt;- thinned$pos&lt;br /&gt;
		chr &amp;lt;- thinned$chr&lt;br /&gt;
		grp &amp;lt;- thinned$grp&lt;br /&gt;
		rm(thinned)&lt;br /&gt;
	} else {&lt;br /&gt;
		logp &amp;lt;- -log10(pvalue)&lt;br /&gt;
	}&lt;br /&gt;
	rm(pos, pvalue)&lt;br /&gt;
	gc()&lt;br /&gt;
&lt;br /&gt;
	#custom axis to print chromosome names&lt;br /&gt;
	axis.chr &amp;lt;- function(side,...) {&lt;br /&gt;
		if(side==&amp;quot;bottom&amp;quot;) {&lt;br /&gt;
			panel.axis(side=side, outside=T,&lt;br /&gt;
				at=((posmax+posmin)/2+posshift),&lt;br /&gt;
				labels=levels(chr), &lt;br /&gt;
				ticks=F, rot=0,&lt;br /&gt;
				check.overlap=F&lt;br /&gt;
			)&lt;br /&gt;
		} else if (side==&amp;quot;top&amp;quot; || side==&amp;quot;right&amp;quot;) {&lt;br /&gt;
			panel.axis(side=side, draw.labels=F, ticks=F);&lt;br /&gt;
		}&lt;br /&gt;
		else {&lt;br /&gt;
			axis.default(side=side,...);&lt;br /&gt;
		}&lt;br /&gt;
	 }&lt;br /&gt;
&lt;br /&gt;
	#make sure the y-lim covers the range (plus a bit more to look nice)&lt;br /&gt;
	prepanel.chr&amp;lt;-function(x,y,...) { &lt;br /&gt;
		A&amp;lt;-list();&lt;br /&gt;
		maxy&amp;lt;-ceiling(max(y, ifelse(!is.na(sig.level), -log10(sig.level), 0)))+.5;&lt;br /&gt;
		A$ylim=c(0,maxy);&lt;br /&gt;
		A;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	xyplot(logp~genpos, chr=chr, groups=grp,&lt;br /&gt;
		axis=axis.chr, ann.settings=ann.settings, &lt;br /&gt;
		prepanel=prepanel.chr, scales=list(axs=&amp;quot;i&amp;quot;),&lt;br /&gt;
		panel=function(x, y, ..., getgenpos) {&lt;br /&gt;
			if(!is.na(sig.level)) {&lt;br /&gt;
				#add significance line (if requested)&lt;br /&gt;
				panel.abline(h=-log10(sig.level), lty=2);&lt;br /&gt;
			}&lt;br /&gt;
			panel.superpose(x, y, ..., getgenpos=getgenpos);&lt;br /&gt;
			if(!is.null(panel.extra)) {&lt;br /&gt;
				panel.extra(x,y, getgenpos, ...)&lt;br /&gt;
			}&lt;br /&gt;
		},&lt;br /&gt;
		panel.groups = function(x,y,..., subscripts, group.number) {&lt;br /&gt;
			A&amp;lt;-list(...)&lt;br /&gt;
			#allow for different annotation settings&lt;br /&gt;
			gs &amp;lt;- ann.settings[[group.number]]&lt;br /&gt;
			A$col.symbol &amp;lt;- gs$col[(as.numeric(chr[subscripts])-1) %% length(gs$col) + 1]    &lt;br /&gt;
			A$cex &amp;lt;- gs$cex[(as.numeric(chr[subscripts])-1) %% length(gs$cex) + 1]&lt;br /&gt;
			A$pch &amp;lt;- gs$pch[(as.numeric(chr[subscripts])-1) %% length(gs$pch) + 1]&lt;br /&gt;
			A$fill &amp;lt;- gs$fill[(as.numeric(chr[subscripts])-1) %% length(gs$fill) + 1]&lt;br /&gt;
			A$x &amp;lt;- x&lt;br /&gt;
			A$y &amp;lt;- y&lt;br /&gt;
			do.call(&amp;quot;panel.xyplot&amp;quot;, A)&lt;br /&gt;
			#draw labels (if requested)&lt;br /&gt;
			if(gs$label$show) {&lt;br /&gt;
				gt&amp;lt;-gs$label&lt;br /&gt;
				names(gt)[which(names(gt)==&amp;quot;text&amp;quot;)]&amp;lt;-&amp;quot;labels&amp;quot;&lt;br /&gt;
				gt$show&amp;lt;-NULL&lt;br /&gt;
				if(is.character(gt$x) | is.character(gt$y)) {&lt;br /&gt;
					peak = which.max(y)&lt;br /&gt;
					center = mean(range(x))&lt;br /&gt;
					if (is.character(gt$x)) {&lt;br /&gt;
						if(gt$x==&amp;quot;peak&amp;quot;) {gt$x&amp;lt;-x[peak]}&lt;br /&gt;
						if(gt$x==&amp;quot;center&amp;quot;) {gt$x&amp;lt;-center}&lt;br /&gt;
					}&lt;br /&gt;
					if (is.character(gt$y)) {&lt;br /&gt;
						if(gt$y==&amp;quot;peak&amp;quot;) {gt$y&amp;lt;-y[peak]}&lt;br /&gt;
					}&lt;br /&gt;
				}&lt;br /&gt;
				if(is.list(gt$x)) {&lt;br /&gt;
					gt$x&amp;lt;-A$getgenpos(gt$x[[1]],gt$x[[2]])&lt;br /&gt;
				}&lt;br /&gt;
				do.call(&amp;quot;panel.text&amp;quot;, gt)&lt;br /&gt;
			}&lt;br /&gt;
		},&lt;br /&gt;
		xlab=xlab, ylab=ylab, &lt;br /&gt;
		panel.extra=panel.extra, getgenpos=getGenPos, ...&lt;br /&gt;
	);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Sample Usage =&lt;br /&gt;
&lt;br /&gt;
First, let us create some fake data to test it with. We will use an imaginary animal that has 10 autosomes. The random sample data is created with &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;rsplus&amp;quot;&amp;gt;&lt;br /&gt;
#FAKE SAMPLE DATA&lt;br /&gt;
createSampleGwasData&amp;lt;-function(chr.count=10, include.X=F) {&lt;br /&gt;
	chr&amp;lt;-c(); pos&amp;lt;-c()&lt;br /&gt;
	for(i in 1:chr.count) {&lt;br /&gt;
		chr &amp;lt;- c(chr,rep(i, 1000))&lt;br /&gt;
		pos &amp;lt;- c(pos,ceiling(runif(1000)*(chr.count-i+1)*25*1e3))&lt;br /&gt;
	}&lt;br /&gt;
	if(include.X) {&lt;br /&gt;
		chr &amp;lt;- c(chr,rep(&amp;quot;X&amp;quot;, 1000))&lt;br /&gt;
		pos &amp;lt;- c(pos,ceiling(runif(1000)*5*25*1e3))&lt;br /&gt;
	}&lt;br /&gt;
	pvalue &amp;lt;- runif(length(pos))&lt;br /&gt;
	return(data.frame(chr, pos,pvalue))&lt;br /&gt;
}&lt;br /&gt;
dd&amp;lt;-createSampleGwasData()&lt;br /&gt;
dd$pvalue[3000] &amp;lt;- 1e-7 #include a significant result&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Using this sample data (chr, pos, and pvalue) we can make the manhattan plot by calling&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;rsplus&amp;quot;&amp;gt;&lt;br /&gt;
manhattan.plot(dd$chr, dd$pos, dd$pvalue)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
[[File:Sample-manhattan-plot-A.png|center]]&lt;br /&gt;
That&amp;#039;s it! But if that were all the function could do, it would be much shorter. There are many other parts of the plot that you can customize.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;sig.level=&amp;lt;/tt&amp;gt; parameter allows you to draw a dotted line indicating the genome-wide significance threshold for your data. If you leave out that parameter, no line will be drawn. A common option would be to incluide &amp;lt;tt&amp;gt;sig.level=5e-8&amp;lt;/tt&amp;gt; for a genome-wide association study.&lt;br /&gt;
&lt;br /&gt;
Notice how the colors alternate between chromosomes. You can change these colors with the &amp;lt;tt&amp;gt;col=&amp;lt;/tt&amp;gt; parameter. You need to pass in a vector of R colors. For example, if you want a more festive plot, try &amp;lt;tt&amp;gt;col=c(&amp;quot;orange&amp;quot;,&amp;quot;blue&amp;quot;,&amp;quot;purple&amp;quot;)&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
By default the function attempts to minimize the number of points drawn by rounding the -log10 p-value and the position and then only plotting the unique combinations. You can disable this default behavior by specifying &amp;lt;tt&amp;gt;should.thin=F&amp;lt;/tt&amp;gt; when you call the function. You can also contol the level of thinning by setting &amp;lt;tt&amp;gt;thin.pos.places=&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;thin.logp.places=&amp;lt;/tt&amp;gt;. These values control the number of decimal places that each value is rounded to. Both of these values default to 2 decimal places.&lt;br /&gt;
&lt;br /&gt;
Furthermore, you are able to pass any additional lattice graphical parameters that you want as well such as &amp;lt;tt&amp;gt;main=&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;ylim=&amp;lt;/tt&amp;gt;, or &amp;lt;tt&amp;gt;par.settings=&amp;lt;/tt&amp;gt;. They will be passed though to the embded &amp;lt;tt&amp;gt;xyplot()&amp;lt;/tt&amp;gt; command.&lt;br /&gt;
&lt;br /&gt;
If your list of chromosomes is non-numeric, you need to bit of extra work. You must make sure the value you pass in for chromosome is an ordered factor, such that chromosomes 1-22 come first, followed by X,Y, and/or MT. An example might be&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;rsplus&amp;quot;&amp;gt;&lt;br /&gt;
#generate sample data (with X) using above function&lt;br /&gt;
dd&amp;lt;-createSampleGwasData(include.X=T)&lt;br /&gt;
#now plot chromosomes in correct order&lt;br /&gt;
manhattan.plot(factor(dd$chr, levels=c(1:10, &amp;quot;X&amp;quot;)), dd$pos, dd$pvalue)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Noteice that the labels on the x-axis in the plot come from the levels of the chr factor. Thus if you have raw data that has chromosomes 1-25 where stands for 23=X, 24,Y, and 25=MT, you can create the appropriate ordered vector with the proper names using &amp;lt;tt&amp;gt;factor(chr, levels=1:25, labels=c(1:22, &amp;quot;X&amp;quot;,&amp;quot;Y&amp;quot;,&amp;quot;MT&amp;quot;))&amp;lt;/tt&amp;gt; where &amp;lt;tt&amp;gt;chr&amp;lt;/tt&amp;gt; is your vector of values 1-25.&lt;br /&gt;
&lt;br /&gt;
In tests, running R to read in GWAS results (2.5 million SNPs) and create a manhattan plot using this function took about 7-10 minutes. The only real concern is how much memory R uses when you read in the data. It is important to only read in the data that you need for the plot to minimize memory; so if your results file contains other columns, you may wish to ignote them using a NULL in &amp;lt;tt&amp;gt;colClasses=&amp;lt;/tt&amp;gt; (see the documentation for &amp;lt;tt&amp;gt;read.table&amp;lt;/tt&amp;gt; for more information).&lt;br /&gt;
&lt;br /&gt;
= Annotating Regions or SNPs =&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;mantahhan.plot&amp;lt;/tt&amp;gt; function provies many options for annotating differnt parts of your plot. For example you may wish to highlight certain gene regions or point out certain SNPs. You can do this with the &amp;lt;tt&amp;gt;annotate=&amp;lt;/tt&amp;gt; parameter. In the simplest case, you can pass in a factor (with the same length as the pvalue vector) which assigns each point to a group. The function assumes the &amp;#039;&amp;#039;&amp;#039;first level&amp;#039;&amp;#039;&amp;#039; of that factor correspondes to the background SNPs, and every other factor will be drawn in a different color, and labeled with their lable name. (Note: you can check the levels and labels of a factor variable in R with &amp;lt;tt&amp;gt;levels()&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;labels()&amp;lt;/tt&amp;gt;). Here is an example of coloring in three gene regions&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;rsplus&amp;quot;&amp;gt;&lt;br /&gt;
#create sample data&lt;br /&gt;
dd&amp;lt;-createSampleGwasData()&lt;br /&gt;
#make annotation factor&lt;br /&gt;
ann&amp;lt;-rep(1, length(dd$pvalue))&lt;br /&gt;
ann[with(dd, chr==1 &amp;amp; pos&amp;gt;=90e3 &amp;amp; pos&amp;lt;110e3)]&amp;lt;-2&lt;br /&gt;
ann[with(dd, chr==4 &amp;amp; pos&amp;gt;=50e3 &amp;amp; pos&amp;lt;80e3)]&amp;lt;-3&lt;br /&gt;
ann[with(dd, chr==6 &amp;amp; pos&amp;gt;=30e3 &amp;amp; pos&amp;lt;50e3)]&amp;lt;-4&lt;br /&gt;
ann&amp;lt;-factor(ann, levels=1:4, labels=c(&amp;quot;&amp;quot;,&amp;quot;GENE1&amp;quot;,&amp;quot;GENE2&amp;quot;, &amp;quot;GENE3&amp;quot;))&lt;br /&gt;
#draw plot with annotation&lt;br /&gt;
manhattan.plot(dd$chr, dd$pos, dd$pvalue, annotate=ann)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Sample-manhattan-plot-B.png|center]]&lt;br /&gt;
&lt;br /&gt;
Notice that the new regions (those other than the first level of the factor) are colored accooring to the default trellis superpose.symbol colors. However, you have a lot of control over how these special regions are drawn and labeled. Rather than passing in a factor to &amp;lt;tt&amp;gt;annotate=&amp;lt;/tt&amp;gt;, you can pass in a list containing your factor as well as additional lists to customize the drawing of each of the different regions. Each region has the following settings:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;rsplus&amp;quot;&amp;gt;&lt;br /&gt;
list(col= pch=, cex=, fill=, &lt;br /&gt;
	label=list(text=, x=,y=,adj=, pos=, offset=, &lt;br /&gt;
		col=, fontface=, fontsize=, show=)&lt;br /&gt;
)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
All of these parmeters have there usual meaning for plotting functions (see &amp;lt;tt&amp;gt;?xyplot&amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt;?ltext&amp;lt;/tt&amp;gt; for more information on these parameters). So when building a list for your annotation,&lt;br /&gt;
your factor must come first, then you can also pass in lists corresponding to each level of your&lt;br /&gt;
factor (including the background SNPs) that contain the values you want to override. Alternatively, you can pass in lists with names corresponding to the labels of your factor. Let&amp;#039;s illustrate with some examples. Say we wanted to change the plotting character of GENE2 to be trangles, we can either do&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;rsplus&amp;quot;&amp;gt;&lt;br /&gt;
manhattan.plot(dd$chr, dd$pos, dd$pvalue, &lt;br /&gt;
    annotate=list(ann, list(), list(), list(pch=17), list()))&lt;br /&gt;
#or&lt;br /&gt;
manhattan.plot(dd$chr, dd$pos, dd$pvalue, &lt;br /&gt;
    annotate=list(ann, &amp;quot;GENE2&amp;quot;=list(pch=17)))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Notice in the first example, there are four &amp;lt;tt&amp;gt;list()&amp;lt;/tt&amp;gt; items in the annotate list, each corresponse to the four levels of the &amp;lt;tt&amp;gt;ann&amp;lt;/tt&amp;gt; factor. In the second example, we specifically set properties for just the &amp;quot;GENE2&amp;quot; level.&lt;br /&gt;
&lt;br /&gt;
So we can also customize how the labels are displayed. You can change the text with any of the following parameters&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;rsplus&amp;quot;&amp;gt;&lt;br /&gt;
	annotate=list(ann, &amp;quot;GENE2&amp;quot;=list(label=&amp;quot;Other Name&amp;quot;))&lt;br /&gt;
	#or&lt;br /&gt;
	annotate=list(ann, &amp;quot;GENE2&amp;quot;=list(label=list(text=&amp;quot;Other Name&amp;quot;)))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
or you can turn off labeling with either of the following&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;rsplus&amp;quot;&amp;gt;&lt;br /&gt;
	annotate=list(ann, &amp;quot;GENE2&amp;quot;=list(label=F))&lt;br /&gt;
	#or&lt;br /&gt;
	annotate=list(ann, &amp;quot;GENE2&amp;quot;=list(label=list(show=F)))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Further more, you can specify an &amp;lt;tt&amp;gt;x=&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;y=&amp;lt;/tt&amp;gt; value ```in a label list``` to control where the label is placed. For &amp;lt;tt&amp;gt;x=&amp;lt;/tt&amp;gt;, you can speicfy an chromosome and position in the format &amp;lt;tt&amp;gt;x=list(chr,pos)&amp;lt;/tt&amp;gt; or you can specify &amp;quot;center&amp;quot; to find the x-value that&amp;#039;s in the exact middle of the region, or &amp;quot;peak&amp;quot; to get the x-value at the SNP with the most significant p-value. The default is &amp;quot;peak&amp;quot;. For the &amp;lt;tt&amp;gt;y=&amp;lt;/tt&amp;gt; parameter, you can specify a -log10 pvalue (not just the regualr pvalue) or &amp;quot;peak&amp;quot; to get the -log10 pvalue for the best SNP in the region. All of these are valid locations:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;rsplus&amp;quot;&amp;gt;&lt;br /&gt;
	annotate=list( ann, &amp;quot;GENE2&amp;quot;=list(label=list(x=&amp;quot;center&amp;quot;)) )&lt;br /&gt;
	annotate=list( ann, &amp;quot;GENE2&amp;quot;=list(label=list(x=&amp;quot;peak&amp;quot;, y=7)) )&lt;br /&gt;
	annotate=list( ann, &amp;quot;GENE2&amp;quot;=list(label=list(x=list(3,5e3))) )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
The default position for the label, in reference to the (x,y) point, is &amp;lt;tt&amp;gt;pos=3&amp;lt;/tt&amp;gt; which indicates the label is to be centered above the point. If you want this to be even a bit higher than than point, you can also increase the offset with &amp;lt;tt&amp;gt;offset=2&amp;lt;/tt&amp;gt; or something similar. For more info on these options, see &amp;lt;tt&amp;gt;?text&amp;lt;/tt&amp;gt;. Here is what the list might locate if we wanted to change the color of a gene region and mvoe the label somewhat:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;rsplus&amp;quot;&amp;gt;&lt;br /&gt;
	annotate=list( ann, &amp;quot;GENE2&amp;quot;=list(col=&amp;quot;green&amp;quot;, label=list(x=&amp;quot;center&amp;quot;, offset=2)) )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The defaults for the first level are taken from the &amp;lt;tt&amp;gt;pch=&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;col=&amp;lt;/tt&amp;gt; parameters you pass to the function. If you want to change the defaults for the additional gene regions, you can set the &amp;lt;tt&amp;gt;ann.default=&amp;lt;/tt&amp;gt; parameter. These are the settings applied to the regions before any of the settings you might specify in the &amp;lt;tt&amp;gt;annotate=&amp;lt;/tt&amp;gt; parameter. For example, if you wanted to make all the highlighed regions use triangles, rather than circles, you could run&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;rsplus&amp;quot;&amp;gt;&lt;br /&gt;
manhattan.plot(dd$chr, dd$pos, dd$pvalue, annotate=ann, ann.default=list(pch=17))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Annotation Helper Function =&lt;br /&gt;
&lt;br /&gt;
While you have a lot of options to put together an annotation list, there are some types of annotations that are quite standard. To help with these cases, you may use this &amp;lt;tt&amp;gt;annotateSNPRegions()&amp;lt;/tt&amp;gt; function to easily create annotations around SNPs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;rsplus&amp;quot;&amp;gt;&lt;br /&gt;
annotateSNPRegions&amp;lt;-function(snps, chr, pos, pvalue, snplist,&lt;br /&gt;
	kbaway=0, maxpvalue=1, labels=c(), col=c(), pch=c()) {&lt;br /&gt;
&lt;br /&gt;
	stopifnot(all(length(snps)==length(chr), length(chr)==length(pos),&lt;br /&gt;
		length(pos)==length(pvalue)))&lt;br /&gt;
	if (length(snplist)==0) stop(&amp;quot;snplist vector is empty&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
	if(any(pos&amp;gt;1e6)) kbaway&amp;lt;-kbaway*1000&lt;br /&gt;
&lt;br /&gt;
	ann&amp;lt;-rep(0, length(snps))&lt;br /&gt;
	for(i in seq_along(snplist)) {&lt;br /&gt;
		si&amp;lt;-which(snps==snplist[i])&lt;br /&gt;
		ci&amp;lt;-chr[si]&lt;br /&gt;
		pi&amp;lt;-pos[si]&lt;br /&gt;
		ann[chr==ci &amp;amp; pos &amp;gt;= pi-kbaway &amp;amp; pos &amp;lt;= pi+kbaway &amp;amp; pvalue&amp;lt;=maxpvalue]&amp;lt;-i&lt;br /&gt;
	}&lt;br /&gt;
	ann&amp;lt;-list(factor(ann, levels=0:length(snplist), labels=c(&amp;quot;&amp;quot;, snplist)))&lt;br /&gt;
	if(length(col)&amp;gt;0 || length(pch)&amp;gt;0 || length(labels)&amp;gt;0) {&lt;br /&gt;
		for(i in seq_along(snplist)) {&lt;br /&gt;
			ann[[ snplist[i] ]] = list()&lt;br /&gt;
			if(length(col)&amp;gt;0) { &lt;br /&gt;
				ann[[ snplist[i] ]]$col = col[ (i-1) %% length(col)+1 ]&lt;br /&gt;
			}&lt;br /&gt;
			if(length(pch)&amp;gt;0) {&lt;br /&gt;
				ann[[ snplist[i] ]]$pch = pch[ (i-1) %% length(pch)+1 ]	&lt;br /&gt;
			}&lt;br /&gt;
                        if(length(labels)&amp;gt;0) {&lt;br /&gt;
                                ann[[ snplist[i] ]]$label = labels[ (i-1) %% length(labels)+1 ]&lt;br /&gt;
                        }&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
	return(ann)&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To use this function, you must pass in snp names, chromosome, position, and pvalue. Then you must specify a list of SNPs that you want to use to identify your regions. Then you can optionally specify a color (&amp;lt;tt&amp;gt;col=&amp;lt;/tt&amp;gt;) or plotting character (&amp;lt;tt&amp;gt;pch=&amp;lt;/tt&amp;gt;) to use for those regions. If you give more than one color (for example), those colors will be cycled over all of the regions. If you supply only one color, the same color will be used for all regions&lt;br /&gt;
&lt;br /&gt;
We can show how to use this function with sample sample data. Here is an example where we identiy 3 gene regions:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;rsplus&amp;quot;&amp;gt;&lt;br /&gt;
#generate fake data&lt;br /&gt;
dd&amp;lt;-createSampleGwasData()&lt;br /&gt;
dd$snp &amp;lt;- paste(&amp;quot;rs&amp;quot;, 1:length(dd$pvalue), sep=&amp;quot;&amp;quot;) #make up SNP names&lt;br /&gt;
#create annotations&lt;br /&gt;
ann&amp;lt;-annotateSNPRegions(dd$snp, dd$chr,dd$pos,dd$pvalue, &lt;br /&gt;
	c(&amp;quot;rs10&amp;quot;, &amp;quot;rs1001&amp;quot;, &amp;quot;rs2005&amp;quot;), &lt;br /&gt;
	labels=c(&amp;quot;GENE1&amp;quot;,&amp;quot;GENE2&amp;quot;,&amp;quot;GENE3&amp;quot;),&lt;br /&gt;
	col=&amp;quot;blue&amp;quot;,&lt;br /&gt;
	kbaway=100&lt;br /&gt;
)&lt;br /&gt;
#draw plot&lt;br /&gt;
manhattan.plot(dd$chr, dd$pos, dd$pvalue, annotate=ann)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= A final example =&lt;br /&gt;
&lt;br /&gt;
Here is the code used to create the image at the top of the page&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;rsplus&amp;quot;&amp;gt;&lt;br /&gt;
dd&amp;lt;-read.table(&amp;quot;/path/to/data.txt&amp;quot;, header=T, as.is=T, sep=&amp;quot;\t&amp;quot;)&lt;br /&gt;
ann&amp;lt;-annotateSNPRegions(dd$MarkerName, dd$CHR, dd$POS, dd$P.value,&lt;br /&gt;
    snplist=c(&amp;quot;rs10994397&amp;quot;,&amp;quot;rs7296288&amp;quot;,&amp;quot;rs736408&amp;quot;,&amp;quot;rs9371601&amp;quot;, &amp;quot;rs12576775&amp;quot;),&lt;br /&gt;
    name=c(&amp;quot;ANK3&amp;quot;,&amp;quot;CHR12&amp;quot;,&amp;quot;ITIH3&amp;quot;,&amp;quot;SYNE1&amp;quot;,&amp;quot;ODZ4&amp;quot;),&lt;br /&gt;
    col=c(&amp;quot;green&amp;quot;,&amp;quot;red&amp;quot;)[c(1,1,1,2,2)], kbaway=50&lt;br /&gt;
)&lt;br /&gt;
png(&amp;quot;mh.png&amp;quot;, width=950, height=400)&lt;br /&gt;
print(manhattan.plot(dd$CHR, dd$POS, dd$P.value,&lt;br /&gt;
	annotate=ann, ann.default=list(label=list(offset=2)),&lt;br /&gt;
	sig.level=5e-8,&lt;br /&gt;
	key=list(background=&amp;quot;white&amp;quot;, border=T, padding.text=2, &lt;br /&gt;
	corner=c(.95, .95), text=list(lab=c(&amp;quot;Known&amp;quot;,&amp;quot;Novel&amp;quot;)), &lt;br /&gt;
	points=list(col=c(&amp;quot;red&amp;quot;,&amp;quot;green&amp;quot;), pch=20))&lt;br /&gt;
	)&lt;br /&gt;
)&lt;br /&gt;
dev.off()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that we use the built-in lattice parameter &amp;lt;tt&amp;gt;key=&amp;lt;/tt&amp;gt; to create a color key for our gene regions. We cannot use &amp;lt;tt&amp;gt;auto.key=&amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt;simpleKey()&amp;lt;/tt&amp;gt; since this technique uses groups differently than standard Lattice does in order to provide greater flexibility.&lt;br /&gt;
&lt;br /&gt;
= Creating Image Files =&lt;br /&gt;
&lt;br /&gt;
If you have a lot of data, drawing the image to the screen may take a long time, even with the default thinning. Similarly, if you write the image to a PDF, you will get a larger image size and it may take a long time to open/print since the location of every point is stored in the PDF. If you create a PNG file, the image size will be a lot smaller since it remembers the final pixels of the image rather than all the points it drew to make those pixels. If you make the image large enough, you probably won&amp;#039;t notice much loss of detail either. Something like&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;rsplus&amp;quot;&amp;gt;&lt;br /&gt;
png(&amp;quot;mymanhattan.png&amp;quot;, width=950, height=500)&lt;br /&gt;
print(manhattan.plot(chr, pos, pvalue, sig.level=5e-8))&lt;br /&gt;
dev.off()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
should work well.&lt;br /&gt;
&lt;br /&gt;
= Alternatives =&lt;br /&gt;
&lt;br /&gt;
Note that Cristen Willer and Serena Sanna have also made many beautiful plots for GWAS data using R base graphics. They have provided a sample script that does many of the same things as the above function, plus takes care of reading in the data, highlighting known SNPs, and making QQ plots. The sample code can be found at&lt;br /&gt;
    snowwhite:/home/cristen/scripts/makeplot_manhattan_qq_forsharing.R&lt;br /&gt;
&lt;br /&gt;
[[Category:Code Samples]]&lt;/div&gt;</summary>
		<author><name>Goncalo</name></author>
	</entry>
</feed>