如何在ggplot图形

时间:2015-08-31 06:33:34

标签: r ggplot2

问题是我想在ggbio plot中为layoutCaryogram函数的不同层添加多个图例。

library(GenomicRanges)
library(ggbio)
df<-data.frame(chromosome=c(9,9,9,9,9,9),start=c(12229,12244,12245,12248,19576961,19792417)
           ,end=c(12229,12244,12245,12248,19576961,19792417),sample1=c("KDNL","CT","IR","IR","DH","DH"),
           marker=c('snp',"snp",'snp',"snp",'ssr',"ssr"))

myideo<-data.frame(chromosome=9,start=1,end=21757032)

然后我改为GRanges对象

> dfGR

GRanges object with 6 ranges and 2 metadata columns:
      seqnames               ranges strand |   sample   marker
         <Rle>            <IRanges>  <Rle> | <factor> <factor>
  [1]        9 [   12229,    12229]      * |     KDNL      snp
  [2]        9 [   12244,    12244]      * |       CT      snp
  [3]        9 [   12245,    12245]      * |       DH      snp
  [4]        9 [   12248,    12248]      * |       DH      snp
  [5]        9 [19576961, 19576961]      * |     KDNL      ssr
  [6]        9 [19792417, 19792417]      * |     KDNL      ssr
  -------
  seqinfo: 1 sequence from an unspecified genome; no seqlengths


> myideoGR
GRanges object with 1 range and 0 metadata columns:
      seqnames        ranges strand
         <Rle>     <IRanges>  <Rle>
  [1]        9 [1, 21757032]      *
  -------
  seqinfo: 1 sequence from an unspecified genome; no seqlengths

尝试绘制并给它一个漂亮的图表

q1 <- ggplot() + layout_karyogram(myideoGR, cytoband = FALSE)

q2=q1 + layout_karyogram(dfGR[dfGR$marker == "snp",], geom ="rect", ylim =c(0, 10), aes(fill=sample,colour=sample)) +
  layout_karyogram(dfGR[dfGR$marker == "ssr",], ylim =c(11, 19), aes(fill=sample,colour=sample)) +
  scale_color_manual(values=c("#22B700","#00C0BA", "#F564E3","#FF6C91" ),name="SNP",breaks=c("CT","IR","KDNL")) +
  scale_fill_manual(values=c("#22B700","#00C0BA", "#F564E3","#FF6C91"),name="SSR",breaks=c("DH","KDNL")) +
  guides(fill = guide_legend(order=2), color = guide_legend(order=1))

但是,我还有其他想要添加到此剧情中的信息

gene_overlapGR


 GRanges object with 7 ranges and 2 metadata columns:
      seqnames               ranges strand |      sample       TRAIT
         <Rle>            <IRanges>  <Rle> | <character> <character>
  [1]        9 [10128837, 10131086]      * |    Sample_5         MXA
  [2]        9 [10128837, 10131086]      * |    Sample_5         MXA
  [3]        9 [10128837, 10131086]      * |    Sample_5         MXA
  [4]        9 [10128837, 10131086]      * |    Sample_5         MXA
  [5]        9 [10338558, 10340355]      * |    Sample_5         MXA
  [6]        9 [10338558, 10340355]      * |    Sample_5         MXA
  [7]        9 [10328808, 10333199]      * |    Sample_5         MXA

我尝试通过下面的代码添加新图,但图例是

q2+ layout_karyogram(gene_overlapGR, geom ="rect",ylim=c(-10,-1),aes(fiil=trait))

有关使用mxa lebeling添加第三个图例的任何建议吗?

0 个答案:

没有答案