For that what you have to do is to get the data from the named variable, refer to the below code:
doPlot = function(var1) {
# Create the plot object
ggobj = ggplot(wdbc_train, aes(x = diagnosis, y=get(var1))) +
geom_boxplot()
# Add some titles and axis labels
ggobj = ggobj + ggtitle(var1) + xlab("diagnosis") + ylab(var1)
}
doPlot = function(var1) {
# Create the plot object
ggobj = ggplot(iris, aes(x = Species, y=get(var1))) + geom_boxplot()
# Add some titles and axis labels
ggobj = ggobj + ggtitle(var1) + xlab("Species") + ylab(var1)
}
p <- lapply(colnames(iris)[-5], doPlot)
library(gridExtra)
grid.arrange(grobs=p)
If you are a beginner and want to know more about R then do check out the following R programming tutorial.