I am using lapply to speed up data exploration. I am making my boxplots for the numeric variables all at once and I'd like to pass the variable name into the plot.
I have tried to define the name and pass it through.
library(ggplot2)
library(mass)
data(Boston)
num_vars = which(sapply(Boston, is.numeric))
ggBox <-function(index) {
X <- index
X_name <- names(index)
ggplot(Boston,aes("X",X)) + geom_boxplot() + ggtitle(X_name)
}
lapply(Boston[names(num_vars)],FUN=ggBox)
I have tried different variants on that and it just passes X or a numeric value, without the name.