[R] ggplot in a function confusion!

2011-08-15 Thread Justin Haynes
Whats going on here? df-data.frame(x=1:10,y=1:10) ggplot()+geom_point(data=df,aes(x=x,y=y)) ## this is the normal usage right? ggplot()+geom_point(data=df,aes(x=df[,1],y=df[,2])) ## but I can also feed it column indices ggplot()+geom_point(aes(x=df[,'x'],y=df[,'y'])) ## or column names. ##

Re: [R] ggplot in a function confusion!

2011-08-15 Thread Dennis Murphy
Hi: Try this: df-data.frame(x=1:10,y=1:10) plot.fun.one - function(dff, x.var, y.var) print(ggplot(dff, aes_string(x = x.var, y = y.var)) + geom_point() ) plot.fun.two - function(dff, x.var, y.var) { x - names(dff)[x.var] y - names(dff)[y.var] print(ggplot(dff, aes_string(x = x, y =