我寫了一個函數來繪製條形圖。但是當我到達面時,'〜'符號讓事情變得困難。如何在函數內編寫facet_wrap(ggplot2)
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
我如何確保「〜」符號被包含在功能?
功能是字符串還是? – JasonWang
如果您從代碼中移除「get」,會發生什麼情況? –
'facet_wrap(paste(「〜」,feature))'。而且,正如@JakeKaupp所說,擺脫所有「get」的情況。 – eipi10