【问题标题】:Controlling margins in a genoPlotR plot_gene_map控制 genoPlotR plot_gene_map 中的边距
【发布时间】:2019-08-05 01:43:42
【问题描述】:

我正在通过genoPlotR R 包生成一个plot_gene_map 图,它给出了一个水平系统发育树,其中与每片叶子对齐的是一个基因组片段。

这是一个简单的例子来说明我的用法和问题:

plot_gene_map 函数需要一个 ade4s' 包 phylog 对象,该对象代表系统发育树:

tree <- ade4::newick2phylog("(((A:0.08,B:0.075):0.028,(C:0.06,D:0.06):0.05):0.0055,E:0.1);")

genoPlotRdna_seg 对象列表(本质上是具有特定列的data.frames),其中列表元素的名称必须与tree 的叶子名称匹配:

dna.segs.list <- list(A=genoPlotR::as.dna_seg(data.frame(name=paste0("VERY.LONG.NAME.A.",1:10),start=seq(1,91,10),end=seq(5,95,10),strand=1,col="black",ly=1,lwd=1,pch=1,cex=1,gene_type="blocks",fill="red")),
                      B=genoPlotR::as.dna_seg(data.frame(name=paste0("VERY.LONG.NAME.B.",1:10),start=seq(1,91,10),end=seq(5,95,10),strand=1,col="black",ly=1,lwd=1,pch=1,cex=1,gene_type="blocks",fill="blue")),
                      C=genoPlotR::as.dna_seg(data.frame(name=paste0("VERY.LONG.NAME.C.",1:10),start=seq(1,91,10),end=seq(5,95,10),strand=1,col="black",ly=1,lwd=1,pch=1,cex=1,gene_type="blocks",fill="green")),
                      D=genoPlotR::as.dna_seg(data.frame(name=paste0("VERY.LONG.NAME.D.",1:10),start=seq(1,91,10),end=seq(5,95,10),strand=1,col="black",ly=1,lwd=1,pch=1,cex=1,gene_type="blocks",fill="yellow")),
                      E=genoPlotR::as.dna_seg(data.frame(name=paste0("VERY.LONG.NAME.E.",1:10),start=seq(1,91,10),end=seq(5,95,10),strand=1,col="black",ly=1,lwd=1,pch=1,cex=1,gene_type="blocks",fill="orange")))

还有genoPlotRannotation对象列表,它们给出坐标信息,也根据tree叶子命名:

annotation.list <- lapply(1:5,function(s){
  mids <- genoPlotR::middle(dna.segs.list[[s]])
  return(genoPlotR::annotation(x1=mids,x2=NA,text=dna.segs.list[[s]]$name,rot=30,col="black"))
})
names(annotation.list) <- names(dna.segs.list)

而对函数的调用是:

genoPlotR::plot_gene_map(dna_segs=dna.segs.list,tree=tree,tree_width=2,annotations=annotation.list,annotation_height=1.3,annotation_cex=0.9,scale=F,dna_seg_scale=F)

这给出了:

如您所见,顶部和右侧的框(基因)名称被截断。

我尝试使用pdfwidthheight,在将图形保存到文件时,以及通过parmar 的边距,但它们没有效果。

  1. 知道如何在不截断名称的情况下显示此图吗?
  2. 目前genoPlotRplot_gene_map 没有实现legend 选项。知道如何添加图例,让我们说在这些标签旁边的正方形中显示这些颜色:

    data.frame(label = c("A","B","C","D","E"), color = c("red","blue","green","yellow ","橙色"))

【问题讨论】:

    标签: r pdf plot margin legend


    【解决方案1】:

    很高兴你喜欢 genoPlotR。

    您的问题没有真正优雅的解决方案,但您可以尝试以下一些方法: - 增加 annotation_height 并减少 annotation_cex - 在注释功能中增加旋转(“rot”) - 使用 xlims 人为地增加 dna_seg 的长度(但这是一个糟糕的 hack)

    对于其余部分(包括图例),您必须使用网格及其视口。

    前 3 个解决方案的混合:

    annotation.list <- lapply(1:5,function(s){
      mids <- genoPlotR::middle(dna.segs.list[[s]])
      return(genoPlotR::annotation(x1=mids, x2=NA, text=dna.segs.list[[s]]$name,rot=75,col="black"))
    })
    names(annotation.list) <- names(dna.segs.list)
    genoPlotR::plot_gene_map(dna_segs=dna.segs.list,tree=tree,tree_width=2,annotations=annotation.list,annotation_height=5,annotation_cex=0.4,scale=F,dna_seg_scale=F, xlims=rep(list(c(0,110)),5))
    

    使用网格获得更好的解决方案:(注意调用 plot_gene_map 中的“plot_new=FALSE”)

    # changing rot to 30
    annotation.list <- lapply(1:5,function(s){
     mids <- genoPlotR::middle(dna.segs.list[[s]])
    return(genoPlotR::annotation(x1=mids,x2=NA,text=dna.segs.list[[s]]$name,rot=30,col="black"))
    })
    names(annotation.list) <- names(dna.segs.list)
    
    
    # main viewport: two columns, relative widths 1 and 0.3
    pushViewport(viewport(layout=grid.layout(1,2, widths=unit(c(1, 0.3), rep("null", 2))), name="overall_vp"))
    # viewport with gene_map
    pushViewport(viewport(layout.pos.col=1, name="geneMap"))
    genoPlotR::plot_gene_map(dna_segs=dna.segs.list,tree=tree,tree_width=2,annotations=annotation.list,annotation_height=3,annotation_cex=0.5,scale=F,dna_seg_scale=F, plot_new=FALSE)
    upViewport()
    # another viewport for the margin/legend
    pushViewport(viewport(layout.pos.col=2, name="legend"))
    plotLegend(…)
    upViewport()
    

    希望有帮助!

    莱昂内尔

    【讨论】:

      【解决方案2】:

      我可以使用哪个函数或包来添加图例? R 基本功能似乎对我不起作用。将显示以下消息:

      直线错误(图例,单位 = “用户”,cex = cex): plot.new 还没有被调用”

      【讨论】:

        猜你喜欢
        • 2014-10-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-11-23
        • 2018-01-07
        • 2014-09-28
        相关资源
        最近更新 更多