Question: SNP and gene density along the chromosomes plots
0
gravatar for Ric
4.0 years ago by
Ric280
Australia
Ric280 wrote:

Hello,
I found here (A: Calculate Gene Density Per Kb And Plot Density Over Position For All Scaffolds O) the below code for for ploting genes  density along the chromosomes. Here (http://ngs-course.readthedocs.org/en/praha-april-2015/04-graphics.html) it is described how to do ploting SNP density along the chromosomes.

How is it possible to combine the two codes together in order to be able to plot SNPs and genes density along the chromosomes (maybe with two trasparent colours)?


    # check if ggplot2 is installed, if so, load it, 
    # if not, install and load it
    if("ggplot2" %in% rownames(installed.packages())){
        library(ggplot2)
    } else {
        install.packages("ggplot2")
        library(ggplot2)
    }

    # import a text file with gene positions
    # columns should be: chr, position (no end or gene name required)
    genes <- read.table("genes.txt",sep="\t",header=T)

    # make sure the chromosomes are ordered in the way you want
    # them to appear in the plot
    genes$chr <- with(genes, factor(chr, levels=paste("chr",c(1:22,"X","Y"),sep=""), ordered=TRUE))

    # make a density plot of genes over the provided chromosomes (or scaffolds ...)
    plottedGenes <- ggplot(genes) + geom_histogram(aes(x=pos),binwidth=1000000) + facet_wrap(~chr,ncol=2) + ggtitle("RefSeq genes density over human genome 19") + xlab("Genomic position (bins 1 Mb)") + ylab("Number of genes")

    # save it to an image
    png("genes.png",width=1000,height=1500)
    print(plottedGenes)
    dev.off()

Thank you in advance.

Mic

density snp ggplot2 R gene • 3.5k views
ADD COMMENTlink modified 4.0 years ago • written 4.0 years ago by Ric280

For bar plots:
http://stackoverflow.com/questions/6957549/overlaying-histograms-with-ggplot2-in-r

Google how to overlay plots, this is the word you are looking for

ADD REPLYlink written 4.0 years ago by stolarek.ir600
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 716 users visited in the last hour