How to plot positions along a chromosome graphic

后端 未结 3 1464
星月不相逢
星月不相逢 2021-02-05 14:16

I would like to generate a plot depicting 14 linear chromosomes for the organism I work on, to scale, with coloured bars at specified locations along each chromosome. Ideally I\

3条回答
  •  盖世英雄少女心
    2021-02-05 15:14

    Just save your barplot call and then call segments to make the marks at an appropriate location. E.g.:

    bp <- barplot(dat$size, border=NA, col="grey80")
    
    with(marks,
      segments(
        bp[Chromosome,]-0.5,
        Position,
        bp[Chromosome,]+0.5,
        Position,
        col=Type,
        lwd=2, 
        lend=1
       )
    )
    

    Data used:

    dat <- structure(list(chromosome = 1:14, size = c(640851L, 947102L, 
    1067971L, 1200490L, 1343557L, 1418242L, 1445207L, 1472805L, 1541735L, 
    1687656L, 2038340L, 2271494L, 2925236L, 3291936L)), .Names = c("chromosome", 
    "size"), class = "data.frame", row.names = c(NA, -14L))
    
    marks <- structure(list(Chromosome = c(3L, 12L, 13L, 5L, 11L, 14L), Position = c(817702L, 
    1556936L, 1131566L, 1041685L, 488717L, 1776463L), Type = structure(c(1L, 
    1L, 1L, 2L, 2L, 2L), .Label = c("A", "B"), class = "factor")), .Names = c("Chromosome", 
    "Position", "Type"), class = "data.frame", row.names = c(NA, 
    -6L))
    

提交回复
热议问题