r - How to use do.call to add elements to a ggplot object? -


objection

i use do.call combine list of layers e main plot g. intention use annotation_custom(ggplotgrob(x)) objects (where x independent ggplot object) overlay main plot with.

  • e: objects of class layerinstance/layer/ggproto
  • g: object of class gg/ggplot

simplified problem

this simplified example uses list e of calls geom_* functions:

library(ggplot2) # data d <- data.frame(a = 1:3, x = 1:3, y = 1:3) # main plot g <- ggplot(d, aes(x, y, label = a)) # plot elements e <- list(geom_point(), geom_text()) 

undesired solution

to combine plot g elements in e, use single elements (which works) in:

g + e[[1]] + e[[2]] 

but intention (for automation reasons) use do.call.

problem

using do.call + , list of g , es fails:

do.call(`+`, c(list(g), e)) # error in .primitive("+")(list(data = list(a = 1:3, x = 1:3, y = 1:3),  :  #   unused argument (<environment>) 

question

how can use do.call, + method , list of g , es correctly?

what's wrong g + e ?


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -