This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to plot proportions of syn/nonsynonymous alleles across the chromosome?

Hi, All,

I want to plot the synonymous and non-synonymous allele frequency over chromosomes, like this plot attached, which the non-synonymous and synonymous SNPs add up to the whole space. https://dl.dropboxusercontent.com/u/88399787/F2.medium.gif

My data looks like this:

ID  Chr pos Type    Allelefrequency
SNP1    1   3245    SYN 0.12
SNP2    1   3569    SYN 0.13
SNP3    1   4503    SYN 0.03
SNP4    1   11590   NONSYN  0.22
SNP5    1   11983   NONSYN  0.14
SNP6    1   12030   NONSYN  0.33

Any input is appreciated

Thanks

rplot

"Any input is appreciated," -- the same could be said by someone trying to answer this question :)
What data do you have for this plot, and what form is it in?

Sorry for the vague question, I've updated it, thanks

1 answer

You can get something pretty similar using R and ggplot2.

First, let's fake up some data similar to yours:

df0 <- data.frame(
   pos = sort(sample(1:10000, 1000)),
   type = sample(c("Syn", "NonSyn"), 1000, prob=c(3/4, 1/4), replace=TRUE)
)

Now, use geom_bar() and percent_format() (from the cales library) to make the plot:

library(ggplot2)
library(scales)
p <- ggplot(df0, aes(pos, fill=type))
p + geom_bar(position="fill", binwidth=100) + scale_y_continuous(labels=percent_format())

You can change the binwidth argument to make the window size smaller or larger, and add colour=white if you want the windows to be distinct.

Thank you so much, David, I finally nailed the plot,

Log in to answer this question.