How to plot allele frequency
1
1
Entering edit mode
6.1 years ago

Hi all,

I have a table that you will see below:

         CHROM_POS   A_Freq      M.F Annotation    N_Chr  POP
1   CM009840.1_932 1.000000 0.000000   nongenic 20.00000 KHUZ
2  CM009840.1_1096 0.666667 0.333333   nongenic 13.33334 KHUZ
3  CM009840.1_1107 0.277778 0.277778   nongenic  5.55556 KHUZ
4  CM009840.1_1177 0.500000 0.500000   nongenic 10.00000 KHUZ
5  CM009840.1_1276 0.555556 0.444444   nongenic 11.11112 KHUZ
6  CM009840.1_1295 0.555556 0.444444   nongenic 11.11112 KHUZ
7  CM009840.1_1518 0.937500 0.062500   nongenic 18.75000 KHUZ
8  CM009840.1_1527 0.000000 0.000000   nongenic  0.00000 KHUZ
9  CM009840.1_1533 0.937500 0.062500   nongenic 18.75000 KHUZ
10 CM009840.1_1630 0.062500 0.062500   nongenic  1.25000 KHUZ

SO, I want to draw a plot like the following plot:

enter image description here

What is the best idea?

SNP R • 2.0k views
ADD COMMENT
2
Entering edit mode
6.1 years ago
zx8754 12k

Here is a start:

library(dplyr)
library(ggplot2)

# example data
set.seed(1); myData <- data.frame(
  A_Freq = runif(1000),
  Annotation = sample(LETTERS[1:3], 1000, replace = TRUE))

# prepare data, use "cut" make "A_Freq" groups
plotDat <- myData %>% 
  mutate(AlleleFrequency = cut(A_Freq, seq(0, 1, 0.25))) %>% 
  group_by(AlleleFrequency, Annotation) %>% 
  summarise(FractionOfSNPs = n()/nrow(myData) * 100)

# then plot
ggplot(plotDat,
       aes(AlleleFrequency, FractionOfSNPs, group = Annotation, col = Annotation)) +
  geom_line() +
  scale_y_continuous(limits = c(0, 100))
ADD COMMENT

Login before adding your answer.

Traffic: 2481 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6