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 classlayerinstance
/layer
/ggproto
g
: object of classgg
/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
, e
s 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
, e
s correctly?
what's wrong g + e
?
Comments
Post a Comment