我正試圖撰寫一個函式,以輸出可用于多個標準化資料框架的圖。 我一直想弄清楚我做錯了什么,但我想不出來。
# function to plot
plotify < - function(data, x, y){
ggplot2:: ggplot(data, aes(x, y))
geom_bar(stat = "identity")
}
plotify(iris, Species, Sepal.Length)
## Error in FUN(X[[i]], ...) : object 'Species' not found
上面的代碼怎么會給我帶來錯誤,但如果要運行下面的代碼,
ggplot(iris, aes(Species, Sepal.Length)) geom_bar(stat = "identity")
我得到了我需要的繪圖?我在寫這個函式的時候是怎么搞砸的呢?
uj5u.com熱心網友回復:
這是關于非標準評價。在這里,你可以使用curly-curly來使其發揮作用
。plotify < - function(data, x, y){
ggplot2::ggplot(data, ggplot2:: aes({{ x }}。 {{ y }}))
ggplot2::geom_bar(stat = "ident")
}
plotify(iris, Species, Sepal.Length)
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/309259.html
標籤:
