控制genoPlotR plot_gene_map中的边距 [英] Controlling margins in a genoPlotR plot_gene_map
问题描述
我正在通过genoPlotR
R
软件包生成一个plot_gene_map
图形,该图形提供了一个水平的系统发育树,其中与每片叶子对齐的是一个基因组片段.
I'm producing a plot_gene_map
figure by the genoPlotR
R
package, which gives a horizontal phylogenetic tree where aligned with each leaf is a genomic segment.
这是一个简单的示例,说明了我的用法和问题:
Here's a simple example that illustrates my usage and problem:
plot_gene_map
函数需要一个ade4
s的程序包phylog
对象,该对象表示系统树:
The plot_gene_map
function requires an ade4
s' package phylog
object which represents the phylogenetic tree:
tree <- ade4::newick2phylog("(((A:0.08,B:0.075):0.028,(C:0.06,D:0.06):0.05):0.0055,E:0.1);")
genoPlotR
的dna_seg
对象的列表(本质上是具有特定列的data.frame
),其中列表元素的名称必须与tree
的叶子的名称匹配:>
A list of genoPlotR
's dna_seg
objects (which are essentially data.frame
s with specific columns), where the names of the list elements have to match the names of the leaves of 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")))
以及genoPlotR
的annotation
对象的列表,这些对象提供坐标信息,也根据tree
树叶来命名:
And a list of genoPlotR
's annotation
objects, which give coordinate information, also named according to the tree
leaves:
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)
哪个给:
如您所见,顶部和右侧框(基因)的名称被切断.
As you can see the top and right box (gene) names get cut off.
在将图形保存到文件中时,我尝试使用pdf
的width
和height
,并使用通过par
的mar
的边距,但是它们没有效果.>
I tried playing with pdf
's width
and height
, when saving the figure to a file, and with the margins through par
's mar
, but they have no effect.
- 有什么主意如何在不切断名称的情况下显示此图吗?
-
当前
genoPlotR
的plot_gene_map
没有实现legend
选项.知道如何添加图例吧,假设这些图例在这些标签旁边以正方形显示了这些颜色:
- Any idea how to display this plot without getting the names cut off?
Currently
genoPlotR
'splot_gene_map
does not have alegend
option implemented. Any idea how can I add a legend, let's say which shows these colors in squares aside these labels:
data.frame(标签= c("A","B","C","D","E"),颜色= c(红色",蓝色",绿色",黄色" ," orange))
data.frame(label = c("A","B","C","D","E"), color = c("red","blue","green","yellow","orange"))
推荐答案
很高兴您喜欢genoPlotR.
Glad that you like genoPlotR.
您的问题没有真正优雅的解决方案,但是您可以尝试以下一些操作: -增加注解高度并减少注解 -增加注释功能中的旋转("rot") -使用xlims人为地增加dna_seg的长度(但这是一个糟糕的技巧)
There are no real elegant solution to your problem, but here are a few things you can attempt: - increase annotation_height and reduce annotation_cex - increase rotation ("rot") in the annotation function - use xlims to artificially increase the length of the dna_seg (but that’s a bad hack)
对于其余部分(包括图例),您必须使用grid及其视口.
For the rest (including the legend), you’ll have to use grid and its viewports.
前三种解决方案的组合:
A blend of the first 3 solutions:
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")
For the better solution with grid: (note the "plot_new=FALSE" in the call to plot_gene_map)
# 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()
希望有帮助!
Lionel
这篇关于控制genoPlotR plot_gene_map中的边距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!