I would suggest that in the long run something like this would be a good idea:
myfun <- function(pred = "weight", resp = "Time", dat = ChickWeight) {
dev.new() ## more general than windows()
ggplot(dat,aes_string(x=pred,y=resp,color="Diet"))+geom_point()
}
myfun()
qplot
does a lot of fancy evaluation which will be fragile (easy to break, hard to understand) in a context where you are passing objects in and out of functions. aes_string
specifies that ggplot
should base its lookup on the value of a string, rather than its usual approach of evaluating a language object (i.e. using "weight"
rather than weight
).