ggplot2绘图调用外部变量有三种方式:
library(ggplot2)
variable = ‘a’
-
Using sym
ggplot(df, aes(x = !!sym(variable)) + geom_histogram()
-
Using .data
ggplot(df, aes(x = .data[[variable]])) + geom_histogram()
-
Using get
ggplot(df, aes(x =get(variable)) + geom_histogram()