I'm writing functions for an R-package which will use a wrapper function for ggpairs
from the package GGally
to plot the output objects of the methods. I would like ggpairs
to be able to use variables not part of the input object
for defining aesthetics but this produces an error message with ggpairs
, see below for a minimal example:
library(GGally)
library(ggplot2)
# The data object
object <- list(x = iris[, 1:2], label = "Iris data")
# The grouping
y <- iris[, 5]
# The plotting function
wrapper <- function(object, mapping = aes()){
ggpairs(object$x, mapping)
}
# This works
wrapper(object)
# This doesn't work
wrapper(object, aes(color = y))
The latter one produces the error message:
Error in .subset(col, i) : object of type 'symbol' is not subsettable
Any trick to get the second plotting command to work without modifying the input object
would be greatly appreciated.