<?xml version='1.0'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:georss="http://www.georss.org/georss" xmlns:atom="http://www.w3.org/2005/Atom" >
<channel>
	<title><![CDATA[BOL: Plot the density of genes in R]]></title>
	<link>https://bioinformaticsonline.com/snippets/view/35417/plot-the-density-of-genes-in-r?</link>
	<atom:link href="https://bioinformaticsonline.com/snippets/view/35417/plot-the-density-of-genes-in-r?" rel="self" type="application/rss+xml" />
	<description><![CDATA[]]></description>
	
	<item>
	<guid isPermaLink="true">https://bioinformaticsonline.com/snippets/view/35417/plot-the-density-of-genes-in-r</guid>
	<pubDate>Fri, 02 Feb 2018 03:19:16 -0600</pubDate>
	<link>https://bioinformaticsonline.com/snippets/view/35417/plot-the-density-of-genes-in-r</link>
	<title><![CDATA[Plot the density of genes in R]]></title>
	<description><![CDATA[<code>#column1 = chromosome name and column2 = start position of the gene

# check if ggplot2 is installed, if so, load it, 
# if not, install and load it
if(&quot;ggplot2&quot; %in% rownames(installed.packages())){
    library(ggplot2)
} else {
    install.packages(&quot;ggplot2&quot;)
    library(ggplot2)
}

# import a text file with gene positions
# columns should be: chr, position (no end or gene name required)
genes &lt;- read.table(&quot;genes.txt&quot;,sep=&quot;\t&quot;,header=T)

# make sure the chromosomes are ordered in the way you want
# them to appear in the plot
genes$chr &lt;- with(genes, factor(chr, levels=paste(&quot;chr&quot;,c(1:22,&quot;X&quot;,&quot;Y&quot;),sep=&quot;&quot;), ordered=TRUE))

# make a density plot of genes over the provided chromosomes (or scaffolds ...)
plottedGenes &lt;- ggplot(genes) + geom_histogram(aes(x=pos),binwidth=1000000) + facet_wrap(~chr,ncol=2) + ggtitle(&quot;RefSeq genes density over human genome 19&quot;) + xlab(&quot;Genomic position (bins 1 Mb)&quot;) + ylab(&quot;Number of genes&quot;)

# save it to an image
png(&quot;genes.png&quot;,width=1000,height=1500)
print(plottedGenes)
dev.off()</code>]]></description>
	<dc:creator>Abhimanyu Singh</dc:creator>
</item>

</channel>
</rss>