You do not need to use get
. You passed the data frame to the function using the dat
argument, so just feed the dat
to ggplot and it will have the data data from its environment.
rf.funct <- function(dat, predictor, feature) { ggplot(dat, aes_string(predictor, "N")) + geom_bar(stat = 'identity') + facet_wrap(feature) }
The predictor
and feature
arguments must be entered as strings. Then you can use aes_string
to indicate aesthetics. facet_wrap
can now take a character vector directly, without the need for a formula (as @WeihuangWong pointed out).
source share