Please consider the following code:
test <- function(x,n){ selection<-names(x)[n] graph <- ggplot(x, aes(factor(selection))) graph + geom_bar() }
you can use aes_string for this purpose. So test should be like this:
aes_string
test
test <- function(x,n){ graph <- ggplot(x, aes_string(x = names(x)[n])) graph + geom_bar() }