gridGraphics :: grid.echo错误:EXPR必须是长度为1的向量

时间:2017-01-02 07:51:13

标签: r plot ggplot2 graphics cowplot

我正在尝试根据to this link使用gridGraphics::grid.echo,因此我可以使用GvizplotTracks ggplot地块与cowplot结合起来s plot_grid

关注Gviz的{​​{3}}和vignette,这就是我的工作:

require(Gviz)
data(geneModels)
gtrack <- GenomeAxisTrack()
itrack <- IdeogramTrack(genome = "hg19", chromosome = as.character(geneModels$chromosome[1]))
grtrack <- GeneRegionTrack(geneModels, genome = "hg19",chromosome = as.character(geneModels$chromosome[1]), name = "Gene Model")

require(gridGraphics)

gwrap_plot <- function(x) {
  tree <- grid::grid.grabExpr(gridGraphics::grid.echo(x))
  u <- grid::unit(1, 'null')
  gtable::gtable_col(NULL, list(tree), u, u)
}

graphics.off()
plotTracks(list(itrack, gtrack, grtrack))
track.plot <- recordPlot()
gwrap_plot(track.plot)

我收到了这个错误:

 Error in switch(x[[2]][[1]]$name, C_abline = C_abline(x[[2]]), C_plot_new = C_plot_new(x[[2]]),  : 
  EXPR must be a length 1 vector 

知道gridGraphics grid.echo Gviz的{​​{1}}情节有什么问题?

1 个答案:

答案 0 :(得分:1)

grid.echo用于基本图形,Gviz似乎使用grid图形,

p1 = grid::grid.grabExpr(plotTracks(list(itrack, gtrack, grtrack), add = TRUE))
p2 = ggplot2::qplot(1:10, 1:10)

gridExtra::grid.arrange(p1, p2, ncol=2)

enter image description here