How to plot positions along a chromosome graphic

后端 未结 3 1463
星月不相逢
星月不相逢 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:04

    data

    { # dataframes
      dfChrSize<-read.table(text="chrName           chrSize
             1         640851
             2         947102
             3        1067971
             4        1200490
             5        1343557
             6        1418242
             7        1445207
             8        1472805
             9        1541735
            10        1687656
            11        2038340
            12        2271494
            13        2925236
            14        3291936", header=T)
    
      dfMarkPos<-read.table(text="chrName   markPos markSize markName
    3          817702 50000 type1
    12         1556936  50000 type2
    13         1131566  50000 type2", header=T, stringsAsFactors=F)
    }
    

    idiogramFISH plot

    install.packages("idiogramFISH")
    library(idiogramFISH) # v. 1.16.1
    
    par(mar=c(0,0,0,0) ) # b l t r
    
    plotIdiograms(dfChrSize,dfMarkPos=dfMarkPos, 
                  karIndex = FALSE,  
                  karHeight = 4,
                  orderChr = "original",
                  chrWidth = .2, 
                  chrSpacing = .5,
                  legendHeight = 2,
                  chromatids = FALSE,
                  rulerIntervalMb = 1000000,
                  useMinorTicks = TRUE,   # ruler 
                  xlimLeftMod = 2,        # modify left margin
                  ylimBotMod = -3,        # modify bottom margin
                  classMbName = "",       # chr. title
                  yPosRulerTitle = 3,     # ruler title pos.
                  xPosRulerTitle = 3)
    

    idiogramFISH coord. + ggplot

    chrAndMarksMap <- mapGGChrMark(dfChrSize,dfMarkPos,chrSpacing = .8)
    
    # ggplot
    
    library(ggplot2)
    
    ggplot() + 
      geom_polygon(aes(x=x,y=y,
                       group=Chr) 
                   ,data=chrAndMarksMap$dataChr
                   ,color="gray"
                   ,fill="gray"
      ) +
      geom_polygon(aes(x=x,y=y,
                       group=id,
                       color=markName,
                       fill=markName) 
                   ,data=chrAndMarksMap$dataMark
      ) +
      theme_classic()+
      scale_x_continuous(breaks=seq(1,nrow(dfChrSize),1)
      ) +
      scale_y_continuous(breaks = seq(0,3500000,500000),
                         labels = seq(0,3.5 , .5)
      ) +
      geom_segment(aes(y=0,yend=3500000,x=-Inf,xend=-Inf)
      )+
      theme(axis.line=element_blank(),
            axis.ticks.x = element_blank(),
            axis.title.x = element_blank(),
            axis.title.y = element_text(angle=0),
            legend.title = element_blank()
            ) +
      ylab("Mb")
    

提交回复
热议问题