I'm sorry to cross post, but I'll try my luck here with this:
I repeat myself a bit here:
Say I have a new ggplot function that accepts lists:
ggplot.list <- function(data = NULL,
mapping = ggplot2::aes(),
...,
environment = parent.frame()) {
p <- ggplot2::ggplot(data=data[[1]],mapping=mapping,..., environment=environment)
p$data_ext <- data[[2]]
p
}
I create my list, and I plot the first data.frame:
l <- list(tibble(x=1:10, y=1:10), tibble(x=1:10+100, y =1:10+200))
ggplot(l) + geom_point(aes(x=x,y=y))
Ideally I would like to create another geom that by default takes the data_ext
from the ggplot object. I could only solve it by piping the plot to a new function:
pipe_point2 <-function (plot, mapping = NULL, data = NULL, stat = "identity", position = "identity",
..., na.rm = FALSE, show.legend = NA, inherit.aes = TRUE)
{
plot + layer(data = plot$data_ext, mapping = mapping, stat = stat, geom = GeomPoint,
position = position, show.legend = show.legend, inherit.aes = inherit.aes,
params = list(na.rm = na.rm, ...))
}
{ggplot(l) + geom_point(aes(x=x,y=y))} %>% pipe_point2(aes(x=x,y=y))
But I would like to create a geom_point2()
which I can then add with +
to not confuse the users of my functions.
Thanks!