r - how to add the third legend in ggplot graph -
the problem want add multiple legend different layer of layoutkaryogram function in ggbio plot.
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)
then change granges object
> dfgr granges object 6 ranges , 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 unspecified genome; no seqlengths > myideogr granges object 1 range , 0 metadata columns: seqnames ranges strand <rle> <iranges> <rle> [1] 9 [1, 21757032] * ------- seqinfo: 1 sequence unspecified genome; no seqlengths
and try plot , give me nice graph
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))
however, have information want add plot
gene_overlapgr granges object 7 ranges , 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
i try add new plot code below legend
q2+ layout_karyogram(gene_overlapgr, geom ="rect",ylim=c(-10,-1),aes(fiil=trait))
any suggestion add third legend mxa lebeling?
Comments
Post a Comment