Alternative notation for multiple additions to a plot

garrettgman edited this page Aug 24, 2010 · 2 revisions
Clone this wiki locally

Perhaps useful, perhaps not.

add <- function(...) {dots <- list(...); Reduce("+", dots)}
add(1, 2, 2) # 5
library(ggplot2)

# usual version
qplot(mpg, wt, data=mtcars, facets = vs ~ am)

last_plot() +
 scale_colour_brewer(palette="Set1") +
 scale_x_continuous("x axis")

# alternative notation
qplot(mpg, wt, data=mtcars, facets = vs ~ am)

add(last_plot(), 
 scale_colour_brewer(palette="Set1"),
 scale_x_continuous("x axis"))

# or

qplot(mpg, wt, data=mtcars, facets = vs ~ am) 
last_plot() + list( scale_colour_brewer(palette="Set1"), scale_x_continuous("x axis")
)