简体   繁体   中英

r code: How can I use a variable name as a string to easily change variables in a formula?

I have a graph I'm making with multiple calls to x and y using the same dataset.

I want to be able to something like

x <- "variable_1"
y <- "variable_2"
y.min <- 100

so that I can have

data %>%
filter(y > y.min)
ggplot(data, aes(x = x, y = y)) + geom_point()

Therefore, if I change x to "variable_3", running the ggplot will display variable_3 on the x-axis instead of variable_1. Also, if I change the y variable, it will filter correctly

将所有内容都放入一个字符串中,然后使用eval(parse(text =“ stringFormula”))执行该字符串

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM