passing parameters to ggplot

would like to create a function that generates graphs using ggplot. For the sake of simplicity, the typical graph may be

ggplot(car, aes(x=speed, y=dist)) + geom_point() 

The function I would like to create is of the type

f <- function(DS, x, y) ggplot(DS, aes(x=x, y=y)) + geom_point()

This however won't work.

One solution would be to pass x and y as string names of columns in data frame DS.

f <- function(DS, x, y) {    
  ggplot(DS, aes_string(x = x, y = y)) + geom_point()  
}

你可能感兴趣的:(passing parameters to ggplot)