我写了一个画条形图的函数。但是当我使用facet wrap时,符号'~'使事情变得困难。
rf.funct <- function(dat, predictor, feature){
ggplot(get(dat), aes(get(predictor), N)) +
geom_bar(stat = 'identity') +
facet_wrap(get(~feature)) # this is where the problem is
}
我尝试了以下操作:
facet_wrap((get(~feature))) # invalid first argument
facet_wrap(paste0("~ ", get(feature))) # object 'feature' not found
如何确保函数中包含“~”符号?
get
,会发生什么? - Jake Kauppfacet_wrap(paste("~", feature))
。正如@JakeKaupp所说,摆脱所有的“get”实例。 - eipi10