0

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.

J. Virta
  • 101
  • 3
  • Can you not just call `ggpairs(cbind(x, y), aes(color = y))` in your function? – Robin Gertenbach Nov 29 '16 at 08:39
  • @RobinGertenbach, thank you for your suggestion. However, I would actually like to pass aesthetics using external variables in general to the plotting function. I edited the question to better reflect this. – J. Virta Nov 29 '16 at 13:53

0 Answers0