library(ggplot2)
# create a ggpacket directly, setting some fixed argument settings
ggpk_simple <- ggpacket() %+% geom_line(color = "red") %+% geom_point()
ggplot(mtcars, aes(x = wt, y = mpg)) + ggpk_simple()
# any non-fixed arguments can be modified in the ggpacket call
ggplot(mtcars, aes(x = wt, y = mpg)) + ggpk_simple(color = "green")
# arguments can be specified for only specific layers by prefixing them
ggplot(mtcars, aes(x = wt, y = mpg)) + ggpk_simple(point.size = 5)
# allow masking of preset arguments by wrapping the ggpacket in a function
ggpk_func <- function(...) {
ggpacket() %+%
geom_line(...) %+%
geom_point(color = "red", ...)
}
ggplot(mtcars, aes(x = wt, y = mpg)) +
ggpk_func(color = "purple", line.linewidth = 2, point.size = 4)
Run the code above in your browser using DataLab